cat & awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat & awk
# 1  
Old 07-09-2008
cat & awk

Hi there,

Can show some hit why i got this error?
For eg i have a.txt in which consist of contents as below

Code:
1|781494-0015|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:13.000|
2|762405-0405|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:17.000|

In fact , i want to perfrom to have field 1 in my new file as below

Code:
cat a.txt | awk -F"|" '{print delete from ab where ab_t=\""\$2"\;"}' | head

syntax error The source line is 1.
 The error context is
                {print "delete from ab where  >>>  ab_t="\ <<< $2"\;"}
 awk: The statement cannot be correctly parsed.


The end result should be something below

Code:
delete from ab where ab_t=1;
delete from ab where ab_t=2;

Please assist

Last edited by radoulov; 07-09-2008 at 07:03 AM.. Reason: added code tags
# 2  
Old 07-09-2008
Use nawk or /usr/xpg4/bin/awk on Solaris.

Code:
zsh-4.3.4% cat file
1|781494-0015|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:13.000|
2|762405-0405|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:17.000|
zsh-4.3.4% awk -F\| '$0="delete from ab where ab_t="$1' file
delete from ab where ab_t=1
delete from ab where ab_t=2

Or use sed:

Code:
sed 's/\([^|]*\).*/delete from ab where ab_t=\1/' file

Or (assuming no IFS characters in the first field):

Code:
printf "delete from ab where ab_t=%s\n" $(cut -d\| -f1 file)


Last edited by radoulov; 07-09-2008 at 07:05 AM..
# 3  
Old 07-09-2008
Code:
while IFS="|" read a b; do printf "delete from ab where ab_t=$a\n";done < file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cat Input & Output to a Log file

Team, we use below command to store the contents in a logfile. cat a.txt > a.log a.txt content is 123 345 Is there any options available to store the command used also? for eg a.log may show as cat a.txt 123 345 (5 Replies)
Discussion started by: sid2013
5 Replies

2. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

3. UNIX for Dummies Questions & Answers

awk+cat

Hi, I am doing this: ll -tr | awk '{print $6, $7, $8, $9}' the result is: Dec 30 2008 text1.txt Mar 4 2009 text2.txt Apr 10 2009 text3.txt and now I want to show the content of $9 using below: ll -tr | awk '{print $6, $7, $8, $9}' ; '{cat $9}' (25 Replies)
Discussion started by: messi777
25 Replies

4. Shell Programming and Scripting

cat & telnet

cat & telnet hello, I need some help on using a file with the cat command. I want to set up a telnet connection with a network device with the ip-adress 10.3.0.1. Just executing the command 'telnet 10.3.0.1' gives a menu. For example, to show the help of the menu, you... (2 Replies)
Discussion started by: michealvh
2 Replies

5. Shell Programming and Scripting

Using cat and awk.......

Im trying to use cat and awk to calculate the total space, then display it using the print command. But something in my script is not correct? cat | awk '{print$1}' | sort -n | grep -v used | awk '{sum += $1} END { p rint sum;}' ??? Any help would be greatly appreciated!! (10 Replies)
Discussion started by: bigben1220
10 Replies

6. Shell Programming and Scripting

Understanding Awk and Cat

Hi Guys, I was recently come across some code to hopefully learn a little bit about putting Shell commands into PHP application to run on a Linux server. However, I don't understand the command AT ALL... and was wondering if anyone can interpret it: cat userIDs.dat | awk '{s=s+1; if... (1 Reply)
Discussion started by: jordRiot
1 Replies

7. UNIX for Dummies Questions & Answers

tr, sed, awk, cat or scripting

I need to change all Newline caracters (\12) to Fieldseparator(\34). tr -A '\12' '\34' <file1> file2 Replace all delete (\177) with Newline (\12) tr -A '\177' '\12' <file2> file3 Put the name of the file first in all rows. awk '{printf "%s\34%s\n", FILENAME,$0} file3 > file4 So far no... (6 Replies)
Discussion started by: MrKlint
6 Replies

8. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

9. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies
Login or Register to Ask a Question