awk command in special character


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users awk command in special character
# 1  
Old 11-29-2011
awk command in special character

Hi,

I want to add below line after end of a file (i.e file1)

&&echo "copy done" >> out.txt

HTML Code:
cat file1
scp user1@server1:/tmp/dir /tmp/dir1
my requirment is

HTML Code:
cat file1
scp user1@server1:/tmp/dir /tmp/dir1 &&echo "copy done" >> out.txt
could any one please help me


Thanks
# 2  
Old 11-29-2011
What's the "cat file1" for?

What do you need help with? You seem to have already been given the answer...
# 3  
Old 11-29-2011
actually I am runing command
Code:
# cat file1
/tmp/dir1/A1
/tmp/dir1/A2

# awk '{print $1 " \&&echo "scp done" >> out.txt"}' file1 > file2
awk: warning: escape sequence `\&' treated as plain `&'

# cat file2
/tmp/dir1/A1 &&echo  >> out.txt
/tmp/dir1/A2 &&echo  >> out.txt

but I want output as
Code:
/tmp/dir1/A1 &&echo "scp done" >> out.txt


Last edited by Scott; 11-29-2011 at 03:44 PM.. Reason: Code tags
# 4  
Old 11-29-2011
You want that output? Or you want that command to be run?

Because you haven't used code tags it's almost impossible to tell the difference between your files and your shell statements.
# 5  
Old 11-29-2011
ohh ..sorry ..!!
is it clear now?

actually I am runing command

Code:
# cat file1
/tmp/dir1/A1
/tmp/dir1/A2

Code:
# awk '{print $1 " \&&echo "scp done" >> out.txt"}' file1 > file2
awk: warning: escape sequence `\&' treated as plain `&'  --> this warning i am getting

Code:
# cat file2
/tmp/dir1/A1 &&echo >> out.txt
/tmp/dir1/A2 &&echo >> out.txt

but I want output as
Code:
#cat file2
/tmp/dir1/A1 &&echo "scp done" >> out.txt
/tmp/dir1/A2 &&echo "scp done" >> out.txt

Image

Last edited by Scott; 11-29-2011 at 03:45 PM.. Reason: Code tags
# 6  
Old 11-29-2011
You certainly don't need to build shell scripts inside awk to do that.

Code:
while read LINE
do
        "$LINE" && echo "$LINE:  scp done"
done < file1 > out.txt

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 11-29-2011
Code:
awk '{print $1 " &&echo \"scp done\" >> out.txt"}' file1 > file2

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to add special character (')

I have a file (input) which contains are below. Member Analytics Engine Enterprise Manager Dev Tutorial I want to change contains as below by using sed command 'Member Analytics Engine'; 'Enterprise Manager'; 'Dev Tutorial'; First, I tried to add (') on every first line by using sed... (8 Replies)
Discussion started by: anshu ranjan
8 Replies

2. Shell Programming and Scripting

awk search for max and min while ignoring special character

I am trying to get a simple min/max script to work with the below input. Note the special character (">") within it. Script awk 'BEGIN{max=0}{if(($1)>max) max=($1)}END {print max}' awk 'BEGIN{min=0}{if(($2)<min) min=($2)}END {print min}' Input -122.2840 42.0009 -119.9950 ... (7 Replies)
Discussion started by: ncwxpanther
7 Replies

3. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

4. Shell Programming and Scripting

Test command with special character not work

Hi all, Case 1 : A=88^M && echo "PASS" Result: PASS Case 2: A=88 && echo "PASS" Result: PASS I would like to know why Case 1 and Case 2 got the same result? What make ^M ignored ? Thanks in advance. (6 Replies)
Discussion started by: montor
6 Replies

5. Shell Programming and Scripting

awk - special character not working

Hi, I am trying to use forward slash in awk. While running the command through console, its working fine but not working while running it through shell script. find . -name "*" -ctime -6 | xargs cat | grep -E -v ^fileName\|^\(\) | awk -v DATE="${CURR_DATE}" -v DATE_LOG="$DATE_SYS" ' ... (4 Replies)
Discussion started by: abhi1988sri
4 Replies

6. Shell Programming and Scripting

Vi special character

When editing a file, vi displays a special character as ^L. Can you tell me the escaped character to be used in awk? And can that escaped character be used in a regexp in both sed and awk? (7 Replies)
Discussion started by: dmesserly
7 Replies

7. Shell Programming and Scripting

a cut-command or special format pattern in awk

Hi i read data with awk, 01.07.2012 00:10 227.72 247.50 1.227 1.727 17.273 01.07.2012 00:20 237.12 221.19 2.108 2.548 17.367 01.07.2012 00:30 230.38 230.34 3.216 3.755 17.412 01.07.2012 00:40 243.18 242.91 4.662 5.172 17.328 01.07.2012 00:50 245.58 245.41 5.179 5.721 17.128... (3 Replies)
Discussion started by: IMPe
3 Replies

8. Shell Programming and Scripting

Regex escape special character in AWK if statement

I am having issues escaping special characters in my AWK script as follows: for id in `cat file` do grep $id in file2 | awk '\ BEGIN {var=""} \ { if ( /stringwith+'|'+'50'chars/ ) { echo "do this" } else if ( /anotherString/ ) { echo "do that" } else { ... (4 Replies)
Discussion started by: purebc
4 Replies

9. Shell Programming and Scripting

Deleteing one character after an special character

I have below line in a unix file, I want to delete one character after "Â". 20091020.Non-Agency CMO Daily Trade Recap Â~V Hybrids The result should be : 20091020.Non-Agency CMO Daily Trade Recap  Hybrids i dont want to use "~V" anywhere in the sed command or any other command, just remove... (1 Reply)
Discussion started by: mohsin.quazi
1 Replies

10. Shell Programming and Scripting

Special Character SED/AWK removal

I have a script that produces an output containing '/.ssh'. I am trying to find a way of parsing only this data from a single line, without removing any other special characters contained within the output as a result of the parse. Any help would be appreciated (6 Replies)
Discussion started by: Raggedranger333
6 Replies
Login or Register to Ask a Question