Parse the next line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse the next line
# 1  
Old 06-05-2013
Parse the next line

If you have a file like this

Code:
Mike
Student:1:4
Boy
Student:3:4
Girl
:master

Then Output is:
Code:
Mike Student:1:4
Boy Student:3:4
Girl :master


Last edited by Scott; 06-05-2013 at 12:21 AM.. Reason: Please use code tags
# 2  
Old 06-05-2013
Have a look at the paste command.

i.e.
Code:
paste - - < file

By default the delimiter is a tab, but you can change that.
This User Gave Thanks to Scott For This Post:
# 3  
Old 06-05-2013
thanks a lot... by the way im having problem with sort..

like
Code:
student20 hey
student1 name
student2 fire
student11 post
student3 back

output:
Code:
student1 name
student2 fire
student3 back
student11 post
student20 hey


Last edited by Scott; 06-05-2013 at 12:40 AM.. Reason: If you can see this..... please use code tags!
# 4  
Old 06-05-2013
I refer you to this recent thread: recent thread goes here!

Code:
$  sort -nk1.8 < file
student1 name
student2 fire
student3 back
student11 post
student20 hey

But, of course, that only works on the exact input you've given. It's always better when doing this kind of thing to pad numbers. Because there will always come a time when you want to use them for something!
This User Gave Thanks to Scott For This Post:
# 5  
Old 06-05-2013
no i did not create the correct output

the output was:
Code:
student1 name
student11 post
student20 hey
student3 back

Moderator's Comments:
Mod Comment Use code tags, please...
# 6  
Old 06-05-2013
By no i did not I presume you meant no it did not...

Please post exactly your input file, and the command you ran.

And, importantly, which OS you are using.

Thanks.
# 7  
Old 06-05-2013
Code:
#cat filename |  sort -nk1.8
student1 name
student11 post
student20 hey
student3 back
#


Last edited by Franklin52; 06-05-2013 at 03:07 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

2. Shell Programming and Scripting

Parse XML line

Hi I am having an xml file with lines like these <d name="T2tt_350_100" title="T2tt_012j_350_100_428p4_pPF_PU" add="1" color="4" ls="1" lw="2" normf="1" xsection="0.070152" EqLumi="94651.6"... (2 Replies)
Discussion started by: Alkass
2 Replies

3. Shell Programming and Scripting

Help with cut and parse the line

I have log file which contains 1000s of lines something like this. INFO |2010-08-29 14:23:37,078|SERIAL_ID=1283109816352|ST=2010-08-2914:23:36|DP_DEVICE=11.22.33.44:4420|TYPE=TransactionLo g|LOG_LEVEL=6|CLASS=Superior... (7 Replies)
Discussion started by: baraghun
7 Replies

4. Shell Programming and Scripting

Parse a line by a space

I am trying to show each word on a separate line, but read in all the words on one command line. Below is the code I have right now: read name MyString=$name name2=" " echo $MyString | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | \ while read char do if then ... (8 Replies)
Discussion started by: tvb2727
8 Replies

5. Shell Programming and Scripting

To parse the line

Hi, I have a line QMNAME(qmgrname) STATUS(RUNNING) Can u jus tell me how to only get the status field ? And also the value of the status whether it is running or not running. -- Thanks (2 Replies)
Discussion started by: julie_s
2 Replies

6. UNIX for Advanced & Expert Users

how do you parse 1 line at a time of file1 ie. line(n) each line into new file

File 1 <html>ta da....unique file name I want to give file=>343...</html> <html>da ta 234 </html> <html>pa da 542 </html> and so on... File 2 343 234 542 and so on, each line in File 1 one also corresponds with each line in File 2 I have tried several grep, sed, while .. read, do,... (4 Replies)
Discussion started by: web_developer
4 Replies

7. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies

8. Shell Programming and Scripting

please help to parse the line

cp4 0 0 170.217.86.10.1421 170.217.86.8.53308 ESTABLISHED tcp4 0 0 170.217.86.10.1421 170.217.86.8.62948 ESTABLISHED tcp4 0 0 170.217.86.10.1421 170.217.86.8.62949 ESTABLISHED tcp4 0 0 170.217.86.10.1421 ... (1 Reply)
Discussion started by: ajaya
1 Replies

9. Shell Programming and Scripting

please help to parse the line

cp4 0 0 170.217.86.10.1421 170.217.86.8.53308 ESTABLISHED tcp4 0 0 170.217.86.10.1421 170.217.86.8.62948 ESTABLISHED tcp4 0 0 170.217.86.10.1421 170.217.86.8.62949 ESTABLISHED tcp4 0 0 170.217.86.10.1421 ... (1 Reply)
Discussion started by: ajaya
1 Replies

10. Shell Programming and Scripting

How to parse a line?

I'm currenting trying to parse the out put of the following command. iostat -xtc -r |grep cmdk0 which produces the output cmdk0,0.2,0.0,1.2,0.0,0.0,0.0,39.7,0,0,0,0,0,0,0,99 I'm then trying to get the data to look like this: rw=0.2 ws=0.0 krs=1.2 kws=0.0 wait=0.0 actv=0.0... (2 Replies)
Discussion started by: edefoe
2 Replies
Login or Register to Ask a Question