Help in printing out information

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in printing out information
# 1  
Old 07-24-2011
Help in printing out information

Hello everyone, I got a small question.
Can I ask if there is any way to shorten the codes at the bottom cuz it looks abit messy.

My Text file contain.. With ":" as a delimiter

Little Prince:The Prince:15.00:188:9
Lord of The Ring:Johnny Dept:56.80:100:38

At the end of the day my output will be..

Little Prince, The Prince, $15.00, 188, 9

Yes its abit messed up I know!! Smilie

echo "`grep "$title" book.txt | cut -d: -f1`, `grep "$title"  book.txt | cut -d: -f2`, $`grep "$title" book.txt | cut -d: -f3`, `grep  "$title" book.txt | cut -d: -f4`, `grep "$title" book.txt | cut -d:  -f5`"

# 2  
Old 07-24-2011
awk -F: -vOFS=", " -vt="$title" '$0~t{$3="$"$3;print}' book.txt

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 07-24-2011
Thank You sir!!
It's amazing how this one sentence can work compared to the C++ I've learned.
If you dun mind can explain to me how it works? So I will be able to make full use of it for future use.
# 4  
Old 07-24-2011
awk -F: set field separator to ":"
-vOFS=", " set output field separator to ", "
-vt="$title" set AWK's variable "t" to the value of shell's variable "$title"
'$0~t match current line against variable "t"
{$3="$"$3;print}' if match is successful, attach "$" sign in front of third field and print whole line
book.txt process file book.txt
This User Gave Thanks to bartus11 For This Post:
# 5  
Old 07-24-2011
Awesome great help!! Smilie
# 6  
Old 07-25-2011
One way through Sed..
sed -n '/'"$TITLE"'/{s/:\([0-9]\)/:$\1/;s/:/,/gp}' inputfile

# 7  
Old 07-26-2011
michaelrozar17 can i ask you about your code?? i dont understand thank
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing, SYSPRINTER, IP printing

Dear readers, We have a printer problem with a UNIX system. The OS is Unix IRIX 6.5 We have connected a printerto the system. If we then make a test print everything goes well . (IP printing) But if we make a print from the "orrga,i"program. Then we see all the printouts stuck within the... (3 Replies)
Discussion started by: SergevdH
3 Replies

2. What is on Your Mind?

Not enough information...

I appreciate the fact that rules are for everyone and I screwed up by not putting a screen printout in code brackets... However, I was a bit dismayed when I received the following and tried to reply to say "Thank you" for sending me the reminder. I could not reply and had no idea what the... (4 Replies)
Discussion started by: RogerBaran
4 Replies

3. UNIX for Dummies Questions & Answers

Some help and information

Well, i am here coz i have this problem: a guy is pinging me so my internet go down when he wants and the same guy is nuking my ventrilo server that i rent in a good website. I want to know how to protect me against this attack and if is possible do the same to him, i know this guy is using a payed... (2 Replies)
Discussion started by: Psike
2 Replies

4. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

5. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

6. Programming

printing out information from pcap file

Hi Folks, i got the following Problem: I want to make an analysis on a pcap file. (diestance between different packets and so on) The difficulty now... it's not a simple Ethernet/ IP/ File, but it's a SS7 file. There are the Layers MTP2 MTP3 and ISUP. My analysis depends on the ISUP Layer. Now... (0 Replies)
Discussion started by: thisismyname
0 Replies

7. UNIX for Dummies Questions & Answers


I'm new to unix and wanted to know if there are UNIX tools/programs on the market that can be loaded onto my laptop or external hard drive that I can use to practice and test what I'm learning. :) (2 Replies)
Discussion started by: Xman0ne
2 Replies

8. Programming

NEED Some Information!!!

Hi guys, do you know where I can find an information or example of creating a remote simulation banking application on UNIX. A client server socket programming using c language to build. using telnet to run. just a simple , add, withdraw, balance function. (1 Reply)
Discussion started by: btx
1 Replies

9. UNIX for Advanced & Expert Users

Printing Problems in unix ... ( Bar-cdoe - Ip Printing)

Hi guys ... i need ur help with some printing problem in unix ... first prob. : i wanna print from my NCR unix to an Win NT , Ip based printing server ( HP JetDirect ) . My issue , is it possible to print directly to an Ip address from unix ? How do i make it work to get any results ?... (3 Replies)
Discussion started by: QuickSilver
3 Replies
Login or Register to Ask a Question