LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-20-2014, 08:21 PM   #1
maddyfreaks
Member
 
Registered: May 2011
Posts: 70

Rep: Reputation: 0
Help Needed with AWK/CUT


$ cat testify.log

Machine Parts 6 DREE
Mufler Strengths 33 XYNC
Siscos 20 09 ABSC
New Part Org Cnt MSP 20 13 ABXX

$ cat /tmp/testify.log | grep -v '^$'|awk 'BEGIN { FS = "[ \t]+" } {for(i=1;i<=NF;i++) print $i;} END {print " "}'
Machine ###>>#here the Column1 for Row 1 is lining into 2 seperate but i want them into a single also the last column has null values jut want to replace null with -
Parts
6
DREE

Mufler
Strengths
33
XYNC

Siscos
20
09
ABSC


how can i acheive the required output... the anticipated output . .

Code:
Machine Parts
-
6
DREE

Mufler Strengths
33
-
XYNC

Siscos
20
09
ABSC

Some times the Column 1 will have 1 to 7 words

Last edited by maddyfreaks; 01-20-2014 at 08:22 PM.
 
Old 01-20-2014, 09:46 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Firstly, please use [code][/code] tags around code or data to make it more readable.

Am I correct in assuming you simply want all data from each line to be on its own line?

If so:
Code:
awk 'RS="\t+"' /tmp/testify.log
Neither cat nor grep are need as awk reads files and can perform regex if needed.

If the above is not suitable you may need to explain further?
 
Old 01-20-2014, 10:44 PM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,482

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
With this InFile ...
Code:
Machine Parts 6 DREE
Mufler Strengths 33 XYNC
Siscos 20 09 ABSC
New Part Org Cnt MSP 20 13 ABXX
... this awk ...
Code:
awk '{p=match($0,/[:0-9:]/);  # p = position of leftmost digit
     p1=substr($0,1,p-1);     # p1 = part 1, everthing left of position p
     p2=substr($0,p);         # p2 = part 2, everthing else
     gsub(/ /,"\n",p2);       # In part 2, replace blanks with line feeds
     print p1; print p2; print " "}' $InFile >$OutFile   # Print results
... produced this OutFile ...
Code:
Machine Parts 
6
DREE
 
Mufler Strengths 
33
XYNC
 
Siscos 
20
09
ABSC
 
New Part Org Cnt MSP 
20
13
ABXX
Daniel B. Martin
 
Old 01-20-2014, 11:04 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
ahhh ... that makes a bit more sense ... well diagnosed Daniel
 
  


Reply


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
[SOLVED] how to cut the last field without using awk anandg111 Linux - Newbie 6 03-13-2012 03:29 PM
How to use grep, cut, or awk to get an IP from a file chudster Linux - General 4 02-03-2010 08:06 PM
Which one is efficient cut cmd or using awk suresh.chola Programming 13 01-25-2010 10:00 AM
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
cut / awk command?? Sammy2ooo Linux - Newbie 1 05-27-2003 06:46 PM


All times are GMT -5. The time now is 04:18 PM.

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