Sponsored Content
Top Forums Shell Programming and Scripting Awk problem: How to express the backtick(') Post 302359230 by patrick87 on Tuesday 6th of October 2009 05:26:27 AM
Old 10-06-2009
Hi,

After I try this command that you suggested,
Code:
for file in "*.txt"; do echo "grep '^@' $file" >> txt.sh; done

It comes out something like :
Code:
grep '^@' *.out

But if I try
Code:
for file in *.txt; do echo "grep '^@' $file" >> txt.sh; done

It comes out something like:
Code:
grep '^@' )' sample1.txt
grep '^@' sample1.txt
grep '^@' )' sample2.txt
grep '^@' sample2.txt
 grep '^@' )' sample3.txt
grep '^@' sample3.txt
 grep '^@' )' sample4.txt
grep '^@' sample4.txt

Can I know why will got four extra file coming out?
Actually my desired output is look like this only:
Code:
grep '^@' sample1.txt
grep '^@' sample2.txt
grep '^@' sample3.txt
grep '^@' sample4.txt

Thanks again for your advance Smilie
Quote:
Originally Posted by pludi
Why so complicated?
Code:
grep '^@' *.txt

Or, if you really want to write a file:
Code:
for file in "*.txt"; do echo "grep '^@' $file" >> txt.sh; done


Last edited by pludi; 10-06-2009 at 09:47 AM.. Reason: code tags!!!
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help with GNU screen: Backtick and Caption.

I'm trying to get GNU screen to show the output of "uptime" for the host being accessed in the current window, but unfortunately, no matter what window I go in, it shows the uptime for the host I originally launched screen in ("adminhost"). Does anyone know how to get this to update from the... (0 Replies)
Discussion started by: akbar
0 Replies

2. Shell Programming and Scripting

By using awk, how to '(backtick)?

Can I know how to express the '(backtick) in awk?! By typing \' ??? (8 Replies)
Discussion started by: patrick87
8 Replies

3. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

4. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

5. Shell Programming and Scripting

Perl: combine Backtick & system() I/O operation?

Hi - Within perl I want to execute a system command. I want to re-direct all the output from the command to a file (@result = `$cmd`;), but I ALSO want the results to be displayed on the screen (system("$cmd"); The reason is this - if the command completes, I want to process the output. If the... (6 Replies)
Discussion started by: jeffw_00
6 Replies

6. Shell Programming and Scripting

Perl: Backtick Errors

When trying to use backticks for system commands, is there a way to read the error messages if a command doesn't execute properly? I have no problem getting the results if the command is properly executed. Ex. my @result = `dir`; foreach my $line (@result) { print "Result = $line";... (2 Replies)
Discussion started by: kooshi
2 Replies

7. Shell Programming and Scripting

use backtick inside awk

Hello, Can't we use backtick operator inside awk. nawk ' BEGIN { RS=""; FS="\</input\>" } { for(i=1;i<=NF;i++) { if ($i~/\"\"/) { print `grep XYZ $i`; print $i } } } ' test In the following code, I need to print $i and some... (8 Replies)
Discussion started by: shekhar2010us
8 Replies

8. Shell Programming and Scripting

[Solved] Backtick and escapes

Hello all, I have a problem with a bash script. It contains an MySQL query, which when I run it 'as is', executes without a problem. When, however, I try to get it to assign its output to a variable, using the backtick, I get errors. So .. /usr/bin/mysql -N -B mydatabase -e 'SELECT... (3 Replies)
Discussion started by: davidm123SED
3 Replies

9. UNIX for Advanced & Expert Users

Grep reg. express problem

When in the vi editor, I can find where the value of variables in COBOL programs (everything is uppercase) get changed with / *ACCT-BALANCE and it will find the last two characters of reserved words such as ACCEPT, FROM, TO, and COMPUTE followed by at least one space before the variable I'm... (2 Replies)
Discussion started by: wbport
2 Replies
All times are GMT -4. The time now is 09:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy