Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-05-2009, 11:27 PM   #1
LQ Newbie
Registered: Feb 2005
Location: Sydney, Australia
Distribution: Slackware 10, Mandrake 10, Fedora Core 2
Posts: 6

Rep: Reputation: 0
Row manipulation with awk

Hi guys,

I want to move (cut) the second row onto the first using awk. I show you what I mean:


Basically, I want to move "test1" next to "test"

test test1


Old 11-05-2009, 11:37 PM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
To get the right logic, you need to show more of the file content. e.g. will you do the stated action ONLY when you find "test" on one line?

If it is that simple, then:

sed '/^test$/{N;s/\n/ /}' filename > newfilename
If finding the word "test" alone on a line, then append the next line and strip out the newline character. Write the result to "newfilename"

Last edited by pixellany; 11-05-2009 at 11:40 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
awk , I need help for awk, just a display function mcandy General 1 12-15-2008 01:21 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
Some comments on awk and awk scripts makyo Programming 4 03-02-2008 06:39 PM
row operation usin awk RudraB Programming 3 03-02-2008 05:42 AM
Shell script to parse csv-like output, row by row utahnix Linux - General 8 12-08-2007 06:03 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:28 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration