Read all lines after a string appears in the file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read all lines after a string appears in the file.
# 1  
Old 10-21-2011
Read all lines after a string appears in the file.

Hi All,

I want to read all lines after a perticular string {SET UP VALUES}apprears in the file.

SET UP values contains direcory, number of days and file type.

Step1: Read all lines below SET UP VALUES string.
Step2: If set up values are not present in each record then read from default section.
Step3: Check that first value in the set up record is valid directory
by cross checking with DIR list.



Code:
 
#{DIR LIST}
PROCESS=/DIR/PATH1
REJECT=/DIR/PATH2
 
#{DEFAULT SECTION}
ALL=$PROCESS,$REJECT
DAYS=80
FORMAT=dat
 
#{SET UP VALUES}
$PROCESS#|#25#|#.dat
$REJECT#|#25#|#.dat
#|#|#|##|#

Please let me know if you need any details.

Thanks and Regards
Nagaraja A
# 2  
Old 10-21-2011
Hi Nagaraja Akkiva,

Two doubts:
1.- What does second step mean?
2.- What must be the output?

Regards,
Birei
# 3  
Old 10-24-2011
a delete script which reads number of days, location and file type as the parameters from the config file.

First, it has to check SET UP VALUES.

For example,

if set up value is "$PROCESS#|#25#|#.dat" then
we have to delete all .dat file older than 25 days from processed directory.

Example second: Here , file directory is null then we have to read for default section mentioned. ALL: i.e $PROCESSED and $REJECTED.

#|#25#|#.xls

Hope this is clear now..

Thanks and Regards
Nagaraja AKkivalli.
# 4  
Old 10-24-2011
Use the below code to get those three data in a variables ->"$PROCESS#|#25#|#.dat"

Code:
A=`cat 1.txt|sed -n '/SET UP VALUES/{n;p;}'|cut -d'|' -f1`
B=`cat 1.txt|sed -n '/SET UP VALUES/{n;p;}'|cut -d'|' -f2`
C=`cat 1.txt|sed -n '/SET UP VALUES/{n;p;}'|cut -d'|' -f3`

Once u got the data to the variable u can excute the IF loop to peform your condition to check the null values
# 5  
Old 10-24-2011
alternate code .. Useless Use of Cat Award
Code:
$ nawk -F\| '/SET UP VALUES/{getline;print $1}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find all lines in file such that each word on that line appears in at least n lines of the file

I have a file where every line includes four expressions with a caret in the middle (plus some other "words" or fields, always separated by spaces). I would like to extract from this file, all those lines such that each of the four expressions containing a caret appears in at least four different... (9 Replies)
Discussion started by: uncleMonty
9 Replies

2. Shell Programming and Scripting

How to read file, and replace certain string with another string?

Hi all, the value in the following file is just an example. It could be a different value/network addresses. Here is my example of initial output in a file name net.txt Initial Output, net.txt The goal is to produce the following format which is to convert from CIDR to Netmask... (6 Replies)
Discussion started by: type8code0
6 Replies

3. Shell Programming and Scripting

Read text between two lines containing a string

Hi, I have text file like the following: Start a b 121 c d End Start a 31 e f End Start p o i k (5 Replies)
Discussion started by: ysrini
5 Replies

4. UNIX for Dummies Questions & Answers

When reading a csv file, counter to read 20 lines and wait for minute then read next 20 till end

Hello All, i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file. Any inputs are appreciated ... (3 Replies)
Discussion started by: victor.s
3 Replies

5. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

6. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

7. Shell Programming and Scripting

input a string and copy lines from a file with that string on it

i have a file1 with many lines. i have a script that will let me input a string. for example, APPLE. what i need to do is to copy all lines from file1 where i can find APPLE or any string that i specify and paste in on file 2 thanks in advance! (4 Replies)
Discussion started by: engr.jay
4 Replies

8. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

9. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

10. UNIX for Dummies Questions & Answers

how to read lines one by one from a file

I have one file in which some commands have written line line i have to read lines from this file(file name passed as avariable) and then i have to execute these commands.. how can i do it? (5 Replies)
Discussion started by: bihani4u
5 Replies
Login or Register to Ask a Question