Help with awk script line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk script line
# 1  
Old 05-17-2011
[SOLVED] Help with awk script line

Hello,

A portion of a script I am writing is supposed to create a text file that outputs lines of the following format:

Code:
url = "ftp://www.example.com/directory/awk_output"

My awk line needs to print the base URL directory and then add a file name to the end of the URL, namely "$1". My current command line looks like this:

Code:
awk '{print "url = \"ftp://www.example.com/directory/" $1\"}' tmp.txt > list.txt

It outputs an error as follows:

Code:
awk: {print "url = \"ftp://www.example.com/directory/" $1\"}
awk:                                                                             ^ backslash not last character on line

I know that the $1 correctly adds to the end of the URL if it is all by itself, but adding the format of url = "URL" causes problems because of having to use the backslash and use literal quote marks. Any help with getting this to work would be appreciated.

Last edited by meridionaljet; 05-17-2011 at 12:46 AM..
# 2  
Old 05-17-2011
Try this

Code:
awk '{print "url = \"ftp://www.example.com/directory/"$1"\""}' tmp.txt > list.txt

regards,
Ahamed

Last edited by ahamed101; 05-17-2011 at 12:37 AM.. Reason: Corrected the code
# 3  
Old 05-17-2011
Quote:
Originally Posted by ahamed101
Try this

Code:
awk '{print "url = \"ftp://www.example.com/directory/\" "$1}' tmp.txt > list.txt

regards,
Ahamed
Thanks for replying. Your code outputs this:

Code:
url = "ftp://www.example.com/directory" $1

What I need is this:

Code:
url = "ftp://www.example.com/directory/$1"

After playing around some more I have gotten it very close with this command:

Code:
awk '{print "url = \"ftp://goes.gsfc.nasa.gov/pub/goeseast-lzw/caribbean/ir4/" $1,"\""}' tmp.txt > list.txt

...which outputs this:

Code:
url = "ftp://www.example.com/directory/$1 "

Which is very close to what I need, but I can't get rid of that white space between the URL and the final quotation mark. I haven't entered any white space in the awk command that I can see, so I'm unsure how to get rid of it in the output.
# 4  
Old 05-17-2011
I have edited the code. Try that

Code:
awk '{print "url = \"ftp://www.example.com/directory/"$1"\""}' tmp.txt > list.txt

regards,
Ahamed
# 5  
Old 05-17-2011
Quote:
Originally Posted by ahamed101
I have edited the code. Try that

Code:
awk '{print "url = \"ftp://www.example.com/directory/"$1"\""}' tmp.txt > list.txt

regards,
Ahamed
That did it. Thanks a bunch.
# 6  
Old 05-17-2011
And the reason why you got a space in your code is because of ,(comma)
, acts as a field separator which is space in this case

regards,
Ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script for pattern match and line break

Hi, I have input which reads like 9089.00 ----- kl jkjjljk lkkk; (909099) 9097.00 ----- HGJJHHJ jcxkjlkjvhvlk jhdkjksdfkhfskd 898.00 ----- HHHH I am trying to do something like this - As soon as I found pattern match "XYZ.00-----" it will insert a line break to the input and will go to... (3 Replies)
Discussion started by: Indra2011
3 Replies

2. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

3. Shell Programming and Scripting

awk script -print line when $2 > $2 of previous line

Hi all, From a while loop I am reading a sorted file where I want to print only the lines that have $1 match and $2 only when the difference from $2 from the previous line is > 30. Input would be like ... AN237 010 193019 0502 1 CSU Amoxycillin AN237 080 ... (2 Replies)
Discussion started by: gafoleyo73
2 Replies

4. Shell Programming and Scripting

awk script creates empty line

I have the following awk script to which I pass the file > 10 0 0 10 0 0 > 12.997 0 5.71132 12.9098 0.0687626 5.48855 12.7506 0.174324 5.13225 12.5913 0.262662 4.80643 12.4316 0.335652 4.50283 12.2717 0.394598 4.21542 12.1113 0.440399 3.93957 11.9506 0.473646 3.67148 11.7894... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

awk script to return the middle line number

I need an awk script that returns the 1st field of the line in the middle of a file. For example, if a file I have has 6 lines, I want it to return the 1st field on line number 3. If a file has 7 lines, I want the script to return the 1st field on line number 4. File1: 3 214 4 219 5 226 2... (8 Replies)
Discussion started by: jontjioe
8 Replies

6. Shell Programming and Scripting

awk script to move a line after the matched pattern line

I have the following text format in a file which lists the question first and then 5 choices after that the explanantion and finally the answer. 1.The amount of time it takes for most of a worker’s occupational knowledge and skills to become obsolete has been declining because of the... (2 Replies)
Discussion started by: nanchil_guy
2 Replies

7. Shell Programming and Scripting

help with awk and new line in script

Hi, I have my script working but only thing is that I am expecting new line for each record but everything is coming in one line. whats wrong with my awk above? Should i use cat instead of echo? I need seperate line for each record. I am getting everything in 1 line (4 Replies)
Discussion started by: dsravan
4 Replies

8. Shell Programming and Scripting

awk/shell script to print each line to a file

Dear People, My query is: have a file, which looks likes this: 10 20 30 40 50 1 2 3 4 5 100 200 300 400 500 what i need is: "PRINT EACH LINE TO AN UNIQUE FILE" desired output: file 1 10 20 30 40 50 file 2 1 2 3 4 5 (3 Replies)
Discussion started by: saint2006
3 Replies

9. Shell Programming and Scripting

Need awk script to add a prefix to each line in file

Hello , I have file with below content : '165567885', '165568443', '165568805', I need an awk script that would add a prefix zero after first ' . Like '0165567885', '0165568443', '0165568805', Please help. Thanks in advance. (5 Replies)
Discussion started by: rmv
5 Replies

10. Shell Programming and Scripting

awk script to compare and insert a line

Hi I want to compare a string at fixed position 10-20 for all the lines starting with 6. if they dont match it should take a copy of a line starting with 1 and insert it before the line starting with 6. How do i this? Please help Eg 1 test 1 765533 7643743 6 yes 3 5363653 373833 7... (9 Replies)
Discussion started by: appsguy616
9 Replies
Login or Register to Ask a Question