Quick egrep / awk help, Please


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Quick egrep / awk help, Please
# 1  
Old 09-25-2008
Quick egrep / awk help, Please

Ok, this may be very simple but I can't find a solution. I have a list of numbered values which I have grepped from a larger life.
ex/
Code:

1:7.54
2:4.52
3:3.22
4:2.11
5:3.59
6:4.36
7:6.88
8:12.28
9:13.37
10:15.6
11:17.66
12:14.25

I need a quick way to organize them (using awk?) into 4 columns.
like this:

1:7.54,2:4.52,3:3.22,4:2.11
5:3.59,6:4.36,7:6.88,8:12.28
9:13.37,10:15.6,11:17.66,12:14.25

Please help, I've been stuck on this for a while.

Thanks

JD
ABS
# 2  
Old 09-25-2008
Code:
<list paste -d, - - - -


Just for the sport, with AWK (nawk or /usr/xpg4/bin/awk on Solaris):

Code:
awk 'ORS=NR%4?",":RS' list

# 3  
Old 09-25-2008
one way:

Code:
#  paste -d"," - - - - < file
1:7.54,2:4.52,3:3.22,4:2.11
5:3.59,6:4.36,7:6.88,8:12.28
9:13.37,10:15.6,11:17.66,12:14.25

# 4  
Old 09-25-2008
using [n]awk:

Code:
#  nawk 'NR%4!=0{printf "%s,", $0;next}1' file
1:7.54,2:4.52,3:3.22,4:2.11
5:3.59,6:4.36,7:6.88,8:12.28
9:13.37,10:15.6,11:17.66,12:14.25

# 5  
Old 09-25-2008
Tytalus,

Can you explain me how the awk code works ?. i am not clear.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Specifying patterns to egrep or awk

given this information: ^\w{3} {11} -]+ kernel:( \]+\.]+\])? ]+: media error \(bad sector\): status=0x]+ { DriveReady SeekComplete Error }$ ^\w{3} {11} -]+ kernel:( \]+\.]+\])? end_request: I/O error, dev ]+, sector ]+ i need to set up monitoring for these strings. but as you can see, they... (2 Replies)
Discussion started by: SkySmart
2 Replies

2. Shell Programming and Scripting

Quick awk question

gawk 'BEGIN{count=0} /^Jan 5 04:33/,0 && /fail/ && /09x83377/ { count++ } END { print count }' /var/log/syslog what is wrong with this code? i want to search the strings "fail" and "09x83377" from all entries. im grabbing all entries in the log starting from Jan 5 04:33 to the end of the... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

Quick awk tip :)

how do i "awk" the date after the from only to compare it on a if statement later . filename example: server1-ips-ultranoob-ok_From_2012_21_12-23:40:23_To_2012_21_12-23:49:45.zip what i want o do is compare only the date from the string in "From_2012_21_12" in this case i only want the... (4 Replies)
Discussion started by: drd0spt
4 Replies

4. Shell Programming and Scripting

Quick egrep help

Hi, could someone tell my why this doesn't work? egrep -c '\b\B+\b' file.txt What is the correct way to count all the words in a file? Welcome to the UNIX and Linux Forums. Please use code tags. Video tutorial on how to use them (3 Replies)
Discussion started by: meightr
3 Replies

5. Shell Programming and Scripting

Patterns with egrep/sed/awk?

I have an array with characters, what I want is if there are other characters in the array which I am looking for than take action that is print BAD ARRAY. So far my code just finds characters but instead I want that it should look for other characters. echo "A B C D F" | egrep -o "D | F" O/P... (5 Replies)
Discussion started by: dixits
5 Replies

6. Shell Programming and Scripting

How to grep/awk/egrep two values for given output?

Dear Friends, I have a command which can result following output. Packet is: /var/adm/yyyy/pkt6043 Intended for network : /vob/repo I would like to retrive pkt6043 and /vob/repo using single command. Blue color test will be always contstant and red color text will be dynamic ... (2 Replies)
Discussion started by: baluchen
2 Replies

7. Shell Programming and Scripting

Quick help on 'awk' needed...!!

bash-2.05$ A=`cat /etc/group |awk -F':' '{if ($1$3$4 ==... (3 Replies)
Discussion started by: ak835
3 Replies

8. Shell Programming and Scripting

Help with AWK -- quick question

Ok. I'm just starting to use AWK and I have a question. Here's what I'm trying to do: uname -n returns the following on my box: ftsdt-svsi20.si.sandbox.com I want to pipe this to an AWK statement and make it only print: svsi20 I tried: uname -n | awk '{ FS = "." ; print $1 }' ... (5 Replies)
Discussion started by: Probos
5 Replies

9. UNIX for Dummies Questions & Answers

grep/awk/egrep?

Hi, The input file "notifications" contains the following string. FRTP has 149 missing batches I want to search for : FRTP has missing batches As the number 149 is not important and will change. The commands I have tried. grep "FRTP has.*missing batches" notifications.txt... (3 Replies)
Discussion started by: whugo
3 Replies
Login or Register to Ask a Question