Printing names using awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing names using awk?
# 1  
Old 04-27-2012
Printing names using awk?

Code:
Mike Harrington:(510) 548-1278:250:100:175                   
Christian Dobbins:(408) 538-2358:155:90:201                   
Susan Dalsass:(206) 654-6279:250:60:50

Need to learn how to print each record preceded by the number of the record using awk.



Code:
awk -F '|' '{print NF}'

would it be something like this?
# 2  
Old 04-28-2012
This looks familiar... You even gave -F: in your last post. Do you know why you tried -F'|' this time? Do you want that as the output delimiter?

The entire record is $0. NF is number of fields in a record (5 for these). NR is the record number.

Code:
awk -F: '{print NR,$0}'

This User Gave Thanks to neutronscott For This Post:
# 3  
Old 04-28-2012
Code:
nl infile

Code:
nl -s: infile

Code:
     1:Mike Harrington:(510) 548-1278:250:100:175                   
     2:Christian Dobbins:(408) 538-2358:155:90:201                   
     3:Susan Dalsass:(206) 654-6279:250:60:50
     4:Archie McNichol:(206) 548-1348:250:100:175
     5:Jody Savage:(206) 548-1278:15:188:150
     6:Guy Quigley:(916) 343-6410:250:100:175
     7:Dan Savage:(406) 298-7744:450:300:275
     8:Nancy McNeil:(206) 548-1278:250:80:75
     9:John Goldenrod:(916) 348-4278:250:100:175
    10:Chet Main:(510) 548-5258:50:95:135
    11:Tom Savage:(408) 926-3456:250:168:200
    12:Elizabeth Stachelin:(916) 440-1763:175:75:300


Last edited by Scrutinizer; 04-28-2012 at 03:06 AM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Bash script for printing folder names and their sizes

1. The problem statement, all variables and given/known data: The task is to create a script that would reproduce the output of 'du' command, but in a different way: what 'du' does is: <size> <folder name>and what is needed is <folder name> <size>We need to show only 10 folders which are the... (3 Replies)
Discussion started by: UncleIS
3 Replies

2. Shell Programming and Scripting

Bash script for printing folder names and their sizes

Good day, everyone! I'm very new to bash scripting. Our teacher gave us a task to create a script that basically does the same job the 'du' command does, with the difference that 'du' command gives an output in the form of <size> <folder name>and what we need is <folder name> <size>As for... (1 Reply)
Discussion started by: UncleIS
1 Replies

3. UNIX for Dummies Questions & Answers

Locate the column names with their values in the file and the printing the same in the other file

I have text file in Linux with two rows : first row conmtain the column nam and the second row contain its value .I nned to fetch few columns first and then redirect the data of those colum in the another file. Any ideas?? (1 Reply)
Discussion started by: Anamica
1 Replies

4. Shell Programming and Scripting

awk to insert a files names

I have a couple of text files which are named as 1.txt 2.txt 1000.txt 11.txt I want to cat/merge the contents of each text file into one single file like this 1 content of 1.txt 2 content of 2.txt 1000 content of 1000.txt 11 content of 11.txt (2 Replies)
Discussion started by: Lucky Ali
2 Replies

5. Shell Programming and Scripting

Extract all proper names from string with awk

I want to extract the proper names with awk from a very long string, like: õ(k): &lt;/span&gt;<br /><a something="pls/pe/person.person?i_pers_id=3694&amp;i_topic_id=2&amp;i_city_id=3372&amp;i_county_id=-1" target="_blank"><b>Gary Oldman</b></a> (George Smiley)<br /><a... (12 Replies)
Discussion started by: lyp
12 Replies

6. Programming

help with printing file names in current directory for C

How do I print all the file names in current directory in C? (6 Replies)
Discussion started by: omega666
6 Replies

7. Shell Programming and Scripting

Assign 1,2,3 according to the names using Awk

Print same letters as 1 or 3 (ex:a/a)and different letters as 2 (ex:a/b) based on Name and subname 1st column indicates main names (ex: ID1 is one main name) and 2nd column indicates sub names (ex: a1 is a subname of ID1) and 3rd column indicates sub-sub names (ex: a/b is a sub-sub name of... (6 Replies)
Discussion started by: ruby_sgp
6 Replies

8. Shell Programming and Scripting

Changing file names with AWK

Dear All, I have some thousands of files in a folder and i need to change those file names without opening the file (no need to change anything in the file content, need to change the file name only). The filenames are as follows: Myfile_name.1_parameter Myfile_name.2_parameter... (6 Replies)
Discussion started by: Fredrick
6 Replies

9. Shell Programming and Scripting

awk computed variable names

Is there a way to do make-style computed variable names in awk? e.g. in make foo = bar bar = wocket I can get "wocket" with $($(foo)) Alternatively can you list all defined variables in awk? thanks (4 Replies)
Discussion started by: craig06y
4 Replies
Login or Register to Ask a Question