Printing out multiple lines with a correct format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing out multiple lines with a correct format
# 1  
Old 02-05-2009
Printing out multiple lines with a correct format

Hello,
This is my first post and I've just started on UNIX in school.

A file name "list" has the following content (excluding the numbers and the bottom part):
Code:
          1         2         3         4         5         6
0123456789012345678901234567890123456789012345678901234567890
IT         Karen Patel    Wimps        Ranjit Singh   FULL
EngineeringKaren Thompson Vegans       John Thompson  PART
Marketing  Ken Whillans   Eagles       Karen Thompson FULL

Names: 11-26
Team Name: 27-39
Partner: 40-53

What I want to do is to output the player's name with the partner's name right next to it. This is what I've done so far:
Code:
echo "Player name?"
	read player 
name=`grep $player........................... list | cut -c12-26 | sed 's;^ *;;;s; *, *;,;g;s; *$;;'`
		target=`grep $player........................... list | cut -c40-54 | sed 's;^ *;;;s; *, *;,;g;s; *$;;'`
		if [ $(echo $name | wc -w) -eq 0 ]
		then
			echo "No such player."
		else
			echo -e "$name's target is $target.\n"
		fi

When the user puts "K" as the player's name, I want the output in this format:
Code:
Karen Patel's partner is Ranjit Singh.
Karen Thompson's partner is John Thompson.
Ken Whillans 's partner is Karen Thompson.

but the output that I get is:
Code:
Ken Whillans
Karen Thompson
Karen Patel's team name is Eagles
Vegans
Wimps.

How can I fix this problem?
Thank You.
# 2  
Old 02-05-2009
Please read the forum rules, you should not post homework(s) Smilie
Code:
# cat file
IT         Karen Patel    Wimps        Ranjit Singh   FULL
EngineeringKaren Thompson Vegans       John Thompson  PART
Marketing  Ken Whillans   Eagles       Karen Thompson FULL

# while read line;do echo "${line:11:14} 's partner is ${line:39:15}"| sed 's.  . .g;s.  . .g;s. $.\..';done <file
Karen Patel 's partner is Ranjit Singh.
Karen Thompson 's partner is John Thompson.
Ken Whillans 's partner is Karen Thompson.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract the correct format of file Name

All, Objective : Extract the correct format of a file name. Please share the script command which will extract the correct format of the file after untarring. Example : If the file is of .csv format then extract filename.csv if the file is having .CSV then extract the same.CSV if the file... (1 Reply)
Discussion started by: Mahesh G
1 Replies

2. Shell Programming and Scripting

Printing multiple lines on the same line between specific text

This is an extract from a large file. The lines that start with fc are ports on a fabric switch. In between each fc port there is information about the port. fc2/12 is up Port description is SEIEDISCOVER-3 Speed is 4 Gbps fc2/13 is down (Administratively down) fc2/14 is up Port... (1 Reply)
Discussion started by: kieranfoley
1 Replies

3. Shell Programming and Scripting

Html output in correct format

Hi, I am running two scripts as below. In Script 1 i am getting correct output in proper HTML format while in script 2 i am not getting output in mail and only html code is getting printed.I want to get the output of script 2. Please guide. 1.IFILE=/home/home01/Report.csv if #Checks... (7 Replies)
Discussion started by: Vivekit82
7 Replies

4. Shell Programming and Scripting

Need Help with grep printing multiple lines.

I need help in printing multiple lines using a grep command. The situation is like this. I have a file that contains large number of lines Now I need to find the the lines in the file such that if the word "AllServiceType" is found then the next line also gets printed. Does anyone... (6 Replies)
Discussion started by: m_usmanayub
6 Replies

5. Shell Programming and Scripting

Trouble printing multiple lines to a new file

Hi, I'm trying to auto generate some php files with a default preamble at the top which is a block comment. The problem is that my output has no new lines and it looks like the output from "ls" is being printed after everyline This is my code #!/bin/bash read -d '' pre_amble... (1 Reply)
Discussion started by: racshot65
1 Replies

6. Shell Programming and Scripting

Dates not comparing correct even the same format

I have the date of the file passed into a variable also current date formatted same passed into a separate variable and compare the two with an if statement and statement always comes up false. Even though I verified the dates. Any help would be awesome. Filecrtdate=`ls -l $i | awk '{print... (19 Replies)
Discussion started by: coderanger
19 Replies

7. Shell Programming and Scripting

Correct a pattern format using sed

hi all I have a file with many lines like aa;bb;cc;dd;ee bb;aa;dd;ee;bb cc;ee;bb;dd;aa ee;cc;bb;aa;dd . . . etc The first line is in right format,Please help me how to use "SED" to change the rest of the lines to the format like line 1 thank all! (1 Reply)
Discussion started by: yuesko
1 Replies

8. Shell Programming and Scripting

Perl: Printing Multiple Lines after pattern match

Hello People, Need some assistance/guidance. OUTLINE: Two files (File1 and File2) File1 has some ids such as 009463_3922_1827 897654_8764_5432 File2 has things along the lines of: Query= 009463_3922_1827 length=252 (252 letters) More stufff here ... (5 Replies)
Discussion started by: Deep9000
5 Replies

9. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

10. UNIX for Advanced & Expert Users

Correct format in a log file

I'm trying to read the output of a .sql script (simple insert and commit oracle pl/slq script) to a log file using a shell script. My problem is I end up with a log file that looks like this: sd12@phenix97:/detain/sd12/logs > cat 20071205_detain_20071206.log 12320496 rows created. Commit... (11 Replies)
Discussion started by: sd12
11 Replies
Login or Register to Ask a Question