bash : Adding numeric order to blank field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash : Adding numeric order to blank field
# 1  
Old 07-19-2012
bash : Adding numeric order to blank field

Hi All,

I have a file menu_opts is as follows

Code:
[root@##### ~]# cat menu_opts
Please select the options
qqqq_usb         STD RETAIL Progs    (Prime time cue advertisements)
qqqq_onc         STD Dealer Progs    (Prime time cue advertisements)
qqqq_zt_usb      STD RETAIL Progs    (Long Format cue advertisements)
qqqq_zt_onc      STD Dealer Progs    (Long Format cue advertisements)
qqqq_us_zt_onc   SA Dealer Progs          (Long Format cue advertisements)
qqqq_dart_usb    WholeSAle RETAIL Progs (Prime time cue advertisements)
qqqq_dart_onc    WholeSAle Dealer Progs (Prime time cue advertisements)
qqqq_dart_zt_usb WholeSAle RETAIL Progs (Long Format cue advertisements)
qqqq_dart_zt_onc WholeSAle Dealer Progs (Long Format cue advertisements)

Im trying to write a shell script, which would display a menu and look as follows

Code:
Please select the options

1] STD RETAIL Progs    (Prime time cue advertisements)
2] STD Dealer Progs    (Prime time cue advertisements)
3] STD RETAIL Progs    (Long Format cue advertisements)
4] STD Dealer Progs    (Long Format cue advertisements)
5] SA Dealer Progs          (Long Format cue advertisements)
6] WholeSAle RETAIL Progs (Prime time cue advertisements)
7] WholeSAle Dealer Progs (Prime time cue advertisements)
8] WholeSAle RETAIL Progs (Long Format cue advertisements)
9] WholeSAle Dealer Progs (Long Format cue advertisements)

Enter a choice or Q to quit

Im facing challenge as I unable to get this display so far following is the progress i made

Code:
[root@##### ~]# cat menu_opts  |head -n 1;echo -e "\n";cat menu_opts |tail -n +2|awk '{gsub(/^ *[^ ]* */," ")}1'



Please select the options


 STD RETAIL Progs    (Prime time cue advertisements)
 STD Dealer Progs    (Prime time cue advertisements)
 STD RETAIL Progs    (Long Format cue advertisements)
 STD Dealer Progs    (Long Format cue advertisements)
 SA Dealer Progs          (Long Format cue advertisements)
 WholeSAle RETAIL Progs (Prime time cue advertisements)
 WholeSAle Dealer Progs (Prime time cue advertisements)
 WholeSAle RETAIL Progs (Long Format cue advertisements)
 WholeSAle Dealer Progs (Long Format cue advertisements)

Please help.
# 2  
Old 07-19-2012
try .

Code:
cat menu_opts |head -n 1;echo -e "\n";cat menu_opts |tail -n +2|awk '{print NR "]" $2 " " $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 " " }'


Last edited by expert; 07-19-2012 at 08:34 AM.. Reason: code tags
# 3  
Old 07-19-2012
Generic solution for more than 9 fields exlcuding first field and giving a numberic order

Thank you expert, is there a more generic way of doing it using awk. The reason being that they may be future additions of the menu_opts file and we may more records the $9.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] sort on numeric part of field

I have ran into a heavy case of PEBCAK*) and could need some advice on what i do wrong: OS is Linux (kernel 2.6.35), sort --version reports "8.5" from 2010, shell is ksh. Originally i had a file with with the following structure: hdisk1 yyy hdisk2 yyy hdisk3 yyy hdisk4 yyy hdisk5 yyy... (2 Replies)
Discussion started by: bakunin
2 Replies

2. Shell Programming and Scripting

Sort numeric order

Hi I am using this cat substitutionFeats.txt | gawk '{$0=gensub(/\t/,"blabla",1);print}' | gawk '{print length, $0}' | sort -n | sort -r and the "sort -n" command doesn't work as expected: it leads to a wrong ordering: 64 Adjustable cuffs 64 Abrasion- 64 Abrasion pas 647 Sanitized 647... (4 Replies)
Discussion started by: louisJ
4 Replies

3. Shell Programming and Scripting

Adding an additional blank field to a file

Hi, I have the following file, I'd like to add an additional blank field to this file This is a tab delimited file, I have tried the same thing on excel, but looking for a unix solution. Here is my input: Country Postal Admin4 StreetBaseName StreetType HUN 2243 Kóka Dózsa György ... (3 Replies)
Discussion started by: ramky79
3 Replies

4. Shell Programming and Scripting

Sort help on non numeric field

Hi, I am unable to sort data on the first field $cat t Jim,212121,Seattle Bill,404404,Seattle Steve,246810,Nevada Scott,212277,LosAngeles Jim,212121,Ohio sort -t"," -k1,2 t Bill,404404,Seattle Jim,212121,Ohio Jim,212121,Seattle Scott,212277,LosAngeles Steve,246810,Nevada (7 Replies)
Discussion started by: Shivdatta
7 Replies

5. Shell Programming and Scripting

Adding total of first field for each number in the second field

Dears, I need a script or command which can find the unique number from the second filed and against that number it adds the total of first field . 17215630 , 0 907043 ,1 201050 ,10 394149 ,4 1964 ,9 17215630, 0 907043 ,1 201050, 10 394149 ,4 1964 ,9 1234234, 55 23 ,100 33 ,67 ... (2 Replies)
Discussion started by: shary
2 Replies

6. Shell Programming and Scripting

Perl script to sort data on second numeric field

Hi, I'm a learner of PERL programming. I've a input file with the below data: SWAT_5, 1703, 2010-09-21 SWAT_6, 2345, 2010-09-21 SWAT_7, 1792, 2010-09-21 SWAT_8, 1662, 2010-09-21 SWAT_9, 1888, 2010-09-21 VXHARP_1, 171, 2010-09-21 I need to sort this data based on the second... (6 Replies)
Discussion started by: ganapati
6 Replies

7. Shell Programming and Scripting

adding field values if field matches

hi i have file as below , i want to add duplicate records like bell_bb to one record with valuve as 15 ( addition of both ) any oneline awk script to achive this ? header 0 CAMPAIGN_NAME 1 Bell_BB 14 Bell_MONTHLY 803 SOLO_UNBEATABLE 644 Bell_BB 1 Bell_MONTHLY 25 SOLO_UNBEATABLE... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

8. Shell Programming and Scripting

sed/awk-adding numeric to a column

I have a txt file as follows Code: Oct 1 file1 4144 Oct 1 file23 5170 Oct 2 file5 3434 Oct 21 file56 2343 I need to add a new column by marking the right log file from current directory. For example populate like this. Please not in the second columt for "1" it has... (2 Replies)
Discussion started by: gubbu
2 Replies

9. Linux

Using sort command to get numeric ascending order

HI everyone, I am trying to use the unix sort command to get a list of numbers sorted in ascending order but having trouble in getting it to work. An example of this issue would be when i am trying to sort the following three number each on a different line "1" , "2" and "116" the sort command... (3 Replies)
Discussion started by: wali4813
3 Replies

10. Shell Programming and Scripting

how to numeric sort on field time

i want to sort time field given by who command as a whole i have tried like this who|sort -n +4 -5 (1 Reply)
Discussion started by: rahulspatil_111
1 Replies
Login or Register to Ask a Question