retrive lines from a file using AWK command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting retrive lines from a file using AWK command
# 1  
Old 05-04-2008
retrive lines from a file using AWK command

Dear friends,
please tell me how to get some required lines from a file and write to another file using AWK command.
i.e.,
if a file contains,

abcdefghigk
12345
lmnopqrstuv

678910
wxyz


please tell me how to get lines(line count is always 2 and it's contineous) mentioned in blue colour from above file and write the same to another file.

thanks in advance,
swamymns
# 2  
Old 05-04-2008
Are they always the second and third lines of the input file? If so, something like:

Code:
awk 'NR==2 || NR ==3' inputfile > outputfile

Alternatively, if it's always the line matching 12345 and the line after it:

Code:
awk '/12345/ { print ; getline; print }' inputfile > outputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk command to find seq lines

I have a below file FILE.cfg JAN_01 VAR1=4 VAR2=SUM VAR3=PRIVATE JAN_10 VAR1=44 VAR2=GUN VAR3=NATUR JAN_20 VAR1=3 VAR2=TQN VAR3=COMMA code: (JAN_10 is argument passed from script) (6 Replies)
Discussion started by: Roozo
6 Replies

2. Shell Programming and Scripting

AWK getline command to read more then two lines

Hello, Am trying to print three lines in a single line using AWK getline command. Below is the command am trying and its displaying only two lines in a single line. Command: awk '{getline n; printf($0,t);next}' Can you please help me ? Thanks, Prince (1 Reply)
Discussion started by: prince1987
1 Replies

3. Shell Programming and Scripting

AWK Command to duplicate lines in a file?

Hi, I have a file with date in it like: UserString1 UserString2 UserString3 UserString4 UserString5 I need two entries for each line so it reads like UserString1 UserString1 UserString2 UserString2 etc. Can someone help me with the awk command please? Thanks (4 Replies)
Discussion started by: Grueben
4 Replies

4. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

5. Shell Programming and Scripting

Retrive the value returned by a command excuted in a remote server using ssh

Hello Everybody, I'm facing a weird problem with the awk command. I try to retrieve in a variable the value returned by a simple ls command. ls /export/home/tmp |tail -1 return a good value (the name of the . But When I try to execute the same command in a remote server using ssh as... (2 Replies)
Discussion started by: Jabarod
2 Replies

6. Shell Programming and Scripting

retrive value from a file

hi i am new to shell scripting i have a properties file like hs=abc hs1=def hs2=ghi now i want to retrive each value and assign it to a variable like var1 = abc please help (7 Replies)
Discussion started by: satish@123
7 Replies

7. Shell Programming and Scripting

to retrive data that appear only once in a file.

hi, I need to get the list of functions that are used more than once in a file list. Thanks in advance (1 Reply)
Discussion started by: anibu
1 Replies

8. UNIX for Advanced & Expert Users

Retrive deleted file's info

I have shell script which reads files, stores its data into Oracle and then deletes tht file. now i want to know creation date and time of deleted files. can we do this? if yes then how? (4 Replies)
Discussion started by: asmita
4 Replies

9. Shell Programming and Scripting

help to retrive data from log file

hi i have following file. where i m trying to retrive data on latest date. let us say we are extracting data from this file for Jun 30 where date is highest date in log file. here i want to take output in other file from first line of Jun 30 to the end of file in short i want retrive... (5 Replies)
Discussion started by: d_swapneel14
5 Replies

10. Shell Programming and Scripting

How to run awk command having multiple lines

Hi, Can u see the code below. set xyz = `cat testt1.txt | awk '/-----/{\ print $1 }\ ' | tail -1` I need to execute it in c shell . What is wrong with the above command. When i write everything on a single line then it is working. Can anybody help me . (0 Replies)
Discussion started by: nani_g
0 Replies
Login or Register to Ask a Question