Question

In: Computer Science

<< UNIX >>> BY this file contains ELMER SOLVER (v 8.4) STARTED AT: 2020/03/18 13:04:22 ParCommInit:...

<< UNIX >>>

BY this file contains

ELMER SOLVER (v 8.4) STARTED AT: 2020/03/18 13:04:22
ParCommInit: Initialize #PEs: 1
MAIN:
MAIN: =============================================================
MAIN: ElmerSolver finite element software, Welcome!
MAIN: This program is free software licensed under (L)GPL
MAIN: Copyright 1st April 1995 - , CSC - IT Center for Science Ltd.
MAIN: Webpage http://www.csc.fi/elmer, Email [email protected]
MAIN: Version: 8.4 (Rev: unknown, Compiled: 2020-02-28)
MAIN: Running one task without MPI parallelization.
MAIN: Running with just one thread per task.
MAIN: HYPRE library linked in.
MAIN: MUMPS library linked in.
MAIN: =============================================================
MAIN:
MAIN:
MAIN: -------------------------------------
MAIN: Reading Model: case.sif
LoadInputFile: Scanning input file: case.sif
LoadInputFile: Loading input file: case.sif
WARNING:: LoadInputFile: There are no BCs in the system!
LoadInputFile: Number of Body Forces: 1
LoadInputFile: Number of Initial Conditions: 0
LoadInputFile: Number of Materials: 1
LoadInputFile: Number of Equations: 1
LoadInputFile: Number of Solvers: 1
LoadInputFile: Number of Bodies: 1
Loading user function library: [HeatSolve]...[HeatSolver_Init0]
LoadMesh: Base mesh name: ./.
LoadMesh: Elapsed REAL time: 0.5294 (s)

Question: I want to create new file that just print between "==" by sing Unix/Linx

this code isn't complete because the output is not correct

#!/bin/bash
while ISF= read line
do

if [[ $line = *"="* ]]

then

echo $line >> Lines

fi

done < "unix"

I REALLY NEED HELP

THANKS,

Solutions

Expert Solution

Answer:

Here is the script, you have to first find the start and end points so that the lines between them can be displayed. To do that first use grep, pass the O/P of grep to cut command which only gives you column. The cut command would display the line lines for both start and end in one single command. Hence to fetch only the first value, pass the O/P of cut command to awk where NR is the line number and $1 is the first column. Similarly, you will have to repeat the command to find the end point. Once start and end points are found, then read the file line by line using a counter. Display those lines between start and end points. That's all. Please find the screenshots for your reference along with the script. Good Luck!!!, drop a comment if you have any questions/ clarifications. I'll be glad to help you.

Script

#!/bin/bash # get the start point of = echo " " start=$(grep -n "=" unix.txt | cut -d : -f 1 | awk 'NR==1{print $1}') echo "The start point of the search is until line : $start" # get the end of = end=$(grep -n "=" unix.txt | cut -d : -f 1 | awk 'NR==2{print $1}') echo "The end point of the search is until line : $end" echo " " count=1; while read line; #read the file line by line do if [[ "$count" -ge $(expr $start + 1) ]] && [[ "$count" -le $(expr $end - 1) ]]; #display lines until count is >=8 and <=18 then echo $line fi count=$(expr $count + 1) #increment the value of count done < unix.txt echo " "


Related Solutions

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT