I'm writing a script that provides a menu to manipulate records. I'm having a problem, however. The first option I'm writing is simply to display all of the records in a supplied file.
The supplied file ('records') currently contains sample data, this data is:
I need to display this data as standard output. It needs to be arranged in 5 columns, each left-justified. The column order is family name (i.e. Jones), first name, telephone number , department number (i.e. 45) and job title. In needs to be sorted in ascending alphabetical order of family name (i.e. Anderson, Brown etc.)
Basically, it should look (something) like this:
Code:
Anderson Sarah 95437869 19 CEO
Brown Sarah 99893878 12 electrician
Couch David 95673456 26 chef
Jones Sarah 95671660 45 sales manager
Smith John 93272658 43 technical manager
Williams Nick 98781987 35 computer officer
I've been trying various solutions using cut and gawk. It's an sh script. Honestly, though, it's getting stupid. Look:
Code:
# Print records option.
1) echo -e "Debug: User has selected print option.\n"
#cut -f2 -d: records | sort
awk '$2 $3 $1 $4 $5 {print}' records
#cut -f3 -d: records
#cut -f1 -d: records
#cut -f4 -d: records
#cut -f5 -d: records
echo -en "\nPress Enter to continue... "
read
;;
It's pretty obvious I haven't a clue how to use (g)awk properly, lol. I'm used to using cut for extracting single columns. I've never had to extract and format a table like this, using unix.
Can anyone help?
Thanks in advance,
Wolfie
Last edited by Silentwolf; 09-03-2008 at 03:09 AM..
Reason: Neatening up formatting.
Hi - I want to interrogate information about my poker hands, sessions are all recorded in a text file in a particular format. Each hand starts with the string <PokerStars> followed by a unique hand reference and other data like date/time. There is then all the information about each hand. My first... (5 Replies)
Hi,
I have a backup report that unfortunately has some kind of hanging indent thing where the first line contains one column more than the others
I managed to get the output that I wanted using awk, but just wanting to know if there is short way of doing it using the same awk
Below is what... (2 Replies)
Hi I am new to shell programming in unix
Please if I can provide help.
I have a file structure of a header record and "N" detail records.
The header record will be the total number of detail records
I need to split the file in 2:
One for the header
Another for all detail records
Could... (1 Reply)
Hi all,
I have a input file say record.txt
hostname IP_address Port_No Version
A 10.10.10.1 80 6.02
B 10.10.10.2 81 6.03
C 10.10.10.3 82 6.04
row 1 has 4 field headings : hostname, IP_address, Port_No and Version.
and from 2nd row onwards the actual records start.
now i need to... (2 Replies)
I have 2 files
"File 1" is delimited by ";" and "File 2" is delimited by "|".
File 1 below (3 record shown):
Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones
Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull
Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Hi everyone.
I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this:
ID: 20
Name: X
Age: 19
ID: 21
Name: Z
ID: 22
Email: xxx@yahoo.com
Name: Y
Age: 19
I want to grep records that... (4 Replies)
Hi,
I want to print 130 fileds using formatted printing in AWK. It looks like
awk '{printf ("%7.2f%7.2f...%7.2\n",$1,$2,...,$130)}' inflie>oufile
But it gives me an error:
Word too long!
Can you please help me with this? Is there another way to do this? (1 Reply)
Below is the code
nawk -F"|" 'tolower($1) ~ "abc" |"" {if (tolower($2) ~"abc"|"") print$0}' file
I want the records from file whose 1st and 2nd field should be either "abc" or "null"
I tried but its giving error.
Appreciate help (2 Replies)
Hi,
My aim is to generate a report using shell script. There are various formats fields coloumns etc.
I want to print in a single line (row) but in different coloumn as given below:
field1 field2 field3 field4
....... ....... ...... .......
The spacing... (1 Reply)
I have a flat file and need to count no of records in the file less the header and the trailer record.
I would appreciate any and all asistance
Thanks
Hadi Lalani (2 Replies)