Always output 6 columns regardless of search results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Always output 6 columns regardless of search results
# 8  
Old 06-02-2014
Thanks RudiC, the awk command worked just fine!

---------- Post updated at 11:08 AM ---------- Previous update was at 10:51 AM ----------

RudCi,

I did find a little glitch, if the last line of data is under 6, then the command does not put the require commas into the output to come up with six columns.
# 9  
Old 06-02-2014
Use
Code:
printf "%s", PR
while (CNT++ < 6) printf ","
printf "\n"

in the END section as well...
# 10  
Old 06-02-2014
Another approach (a bit too long for one line)
Code:
awk '{n=substr($1,1,2); c=$0} n!=p{if(p){$0=s; s=x; $f=$f; print} p=n} {s=s c FS} END{$0=s; $f=$f; print}' f=6 OFS=, file

# 11  
Old 06-02-2014
Quote:
Originally Posted by RudiC
Use
Code:
printf "%s", PR
while (CNT++ < 6) printf ","
printf "\n"

in the END section as well...
I am sorry, I cannot figure out how this is supposed to be added into the original command

---------- Post updated at 04:27 PM ---------- Previous update was at 04:25 PM ----------

Quote:
Originally Posted by Scrutinizer
Another approach (a bit too long for one line)
Code:
awk '{n=substr($1,1,2); c=$0} n!=p{if(p){$0=s; s=x; $f=$f; print} p=n} {s=s c FS} END{$0=s; $f=$f; print}' f=6 OFS=, file

I cannot make this work, it error-ed out.
# 12  
Old 06-02-2014
What error did you get? What is your OS and version?
This User Gave Thanks to Scrutinizer For This Post:
# 13  
Old 06-03-2014
Instead of END {print PR} use
Code:
END {printf "%s", PR 
     while (CNT++ < 6) printf "," 
     printf "\n"}

This User Gave Thanks to RudiC For This Post:
# 14  
Old 06-03-2014
Thanks, that worked!

---------- Post updated at 07:49 AM ---------- Previous update was at 07:41 AM ----------

Quote:
Originally Posted by Scrutinizer
What error did you get? What is your OS and version?
I am on a SunOS 5.10 at a Bash prompt. The awk man page does not tell me the version of awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

Search Results (Search, New, and Today's Topics) Animation Switch

Hey, I added an animation switch on the search results page; so by default the thread previews are off, but if you want to look at them, just click on the green button and the thread previews will turn on (and back off). See image and attached animation: ... (1 Reply)
Discussion started by: Neo
1 Replies

2. Shell Programming and Scripting

Finding files with the name of the results of another search

Dear All, I have a file with this name= xx-nnnn.csv , I has texts in this format, 231048975938093056;234317862284705793;609384034;14955353;1344700706000;1; 231048975938093056;234317958632054785;715450794;52422878;1344700729000;1;... (10 Replies)
Discussion started by: davidfreed
10 Replies

3. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

4. Shell Programming and Scripting

awk - Matching columns between 2 files and reordering results

I am trying to match 4 colums (first_name,last_name,dob,ssn) between 2 files and when there is an exact match I need to write out these matches to a new file with a combination of fields from file1 and file2. I've managed to come up with a way to match these 2 files based on the columns (see below)... (7 Replies)
Discussion started by: ambroze
7 Replies

5. Shell Programming and Scripting

AWK - no search results

Hi all, I'm new to awk and I'm experiencing syntax error that I don't know how to resolve. Hopefully some experts in this forum can help me out. I created an awk file that look like this: $ cat myawk.awk BEGIN { VAR1=PATTERN1 VAR2=PATTERN2 } /VAR1/ { flag=1 } /VAR2/ { flag=0 } {... (7 Replies)
Discussion started by: hk18
7 Replies

6. Shell Programming and Scripting

Operations on search results

Hi, I am a newbie at Unix scritping, and I have a question. Looking at the search functionality on Unix. Here I have a structure root---------dir1 ------- file1, file2, file3 |_____dir2 ______file1@, file4 |_____dir3_______file1@, file5 Under root directory, I... (4 Replies)
Discussion started by: nj302
4 Replies
Login or Register to Ask a Question