change RS in the middle


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change RS in the middle
# 1  
Old 01-28-2007
change RS in the middle

in AWK, how can I change the RS (record separator) in the middle of awk command.

for example:

gawk 'NR==FNR { key[$1]++;next }; RS="?"; $1 in key' file1 file2

in above, I put RS="?" in the middle to change the value of RS to "?" right after the file1 has been processed. when it begins to process file2, It should use the new RS to break the file. But it seems not to work that way as I expect.

how can I achieve that?
# 2  
Old 01-30-2007
i think you should do it on two steps

but dont count on me didnt use awk for awhile in advanced scripting
# 3  
Old 01-31-2007
Try something like that (not tested) :
Code:
gawk 'NR==FNR { key[$1]++;next } $1 in key' file1 RS="?" file2


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding new column in the middle

Hi , I need to add few new columns in existing file .Any help would be great ex: existing file name,typ,add,dept New file(com1,sal are new) name,com1,type,sal,add,dept Thanks, mohan (1 Reply)
Discussion started by: mohan705
1 Replies

2. UNIX for Dummies Questions & Answers

How to separate First,Middle and Last Name from Full name

How to separate First,Middle and Last Name from Full Name? For Example: I/O :- 1) Ashok Kumar Requied Output: First Name:Ashok Middle Name: Last Name:Kumar I/O :- 2) Ashok K Kumar Requied Output: First Name:Ashok Middle Name:K Last Name:Kumar I/O :- 3) Ashok K R Kumar Requied Output:... (1 Reply)
Discussion started by: AhmedLakadkutta
1 Replies

3. Shell Programming and Scripting

How to read from middle of a file for a particular text

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the file. From the end go up to find a particular text. From this particular text till the end of... (3 Replies)
Discussion started by: kashriram
3 Replies

4. UNIX for Dummies Questions & Answers

printing only the middle word between two patterns

How would I print the word "and" between the words "FOO" and BAR" using sed? My file has three words in it FOO and BAR. I only want the word "and". Thanks every one. (7 Replies)
Discussion started by: tigta09
7 Replies

5. Shell Programming and Scripting

add a word in the middle

I have a file where in I need to add gctunit1/gtdivcompebb1/ after the = sign for example: gtfix31/gctunit_gtdivcompebb1/csclkswcompbypassstepgnnnh = gctunit1/gtdivcompebb1/csclkswcompbypassstepgnnnh (3 Replies)
Discussion started by: pitagi
3 Replies

6. Shell Programming and Scripting

add text in the middle of file

Can anyone help me pls? I want to add a text into the middle of file. I've writtenthe following script text to add="$1" file="$2" lines=$(wc -l $2) half_lines=$(expr $lines / 2) head -$half_lines $2 > temp echo "text to add" >> temp ((half_lines=$half_lines + 1)) tail -$half_lines $2... (6 Replies)
Discussion started by: relle
6 Replies

7. Shell Programming and Scripting

How to process from middle of a file?

Hi There. I have a file like this . a nnnn sds b ssss fdefd c sdfd dsfd sdfds ... ... Summary t1 t2 t3 t4 s1 s2 s3 s4 f1 f2 f3 f4 .. How to use awk to begin process this file from the line that contains "Summary"? Thanks! louis (12 Replies)
Discussion started by: javacore
12 Replies

8. Shell Programming and Scripting

How to 'sed' the middle line?

Hi, If I have 90 lines and I want to print the 45th line, is there a quick sed command for this? thx. (7 Replies)
Discussion started by: g_jumpin
7 Replies

9. UNIX for Dummies Questions & Answers

Selecting the middle date!

Hi everyone really need some help with this one. Ive to write a script where the middle date has to be checked and made sure that it is the current date. 281220032812200328122003 This is the format ive to check the date in the middle is the current date. Can anyone help me with this... (14 Replies)
Discussion started by: vcardo10
14 Replies
Login or Register to Ask a Question