awk redirection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk redirection
# 8  
Old 10-07-2010
hi ygemici

thanx for ur reply i will try this thing tomorrow

but the thing is in my file $1 exits in my $file and i need to replace it with some variable that's y i added this
but seriously output file is getting generated but not the content
i tried many times but still not output is there any alternative way to use beside awk i think sed also do it
Code:
sed "s/\(.*_\)\(....\)\(.*$\)/\1$a\3/" $file > $c

even this is not working
don't know what is not working and why output file is having no records

Last edited by Franklin52; 10-08-2010 at 03:30 AM.. Reason: Please use code tags, thank you
# 9  
Old 10-07-2010
Code:
nawk 'FNR==1 {$1="zzz"}1' $file > $c

# 10  
Old 10-07-2010
can you write a sample input file?
# 11  
Old 10-08-2010
hi everyone in my previous post i wrote one command
Code:
#>awk ' { if(NR==1) { $1="zzz" } ' $file > $c

and i was saying file c is created with 0 sixe now i understand why it is creating 0 sixe
see the problem is if u r using awk and redirecting the output u must use
Code:
#>awk ' { if(NR==1) { $1="zzz";print } ' $file > $c

print statment then only it will write .

it works Smilie

thankx everyone who helped me in this

Last edited by Franklin52; 10-08-2010 at 03:30 AM.. Reason: Please use code tags, thank you
# 12  
Old 10-08-2010
good works to you..
and you can use instead of the code
Code:
a=100
b=`echo $file  | cut -d_ -f4 | cut -d. -f1
c=`echo $file | sed "s/$b/$a/"

to
Code:
c=`echo $file | sed 's/\(.*\)_[0-9][0-9][0-9][0-9]\(_*[0-9]*\)/\1_100\2/'`

regards
ygemici
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk file redirection issue

So I'm writing a script which tries to parse human-readable addresses. Part of it is this: print $2, implode(A,1,AN," "), CITY, PROV, POST, COUNTRY, CITYCOUNT>2; CITYCOUNT is a variable between 0 and 3 counting the number of words in a city name. I'm trying to prnt 1 wherever that's greater... (5 Replies)
Discussion started by: Corona688
5 Replies

2. UNIX for Dummies Questions & Answers

little problem of file redirection (awk)

I almost reach my objective (Youhouuu !!!!) But I really don't understand why it doesn't work until the end... :wall: For clarity's sake I am taking a very simple example. The operations I am doing in the script (gsub and print) really don't have any importance !!! I just matter about... (10 Replies)
Discussion started by: beca123456
10 Replies

3. UNIX for Dummies Questions & Answers

about different redirection

explain the redirections 1>, 2>, 3>, ..... and 1< ,2<,3<..... where we use these things thanks Thread moved from AIX forum (2 Replies)
Discussion started by: tsurendra
2 Replies

4. Shell Programming and Scripting

I/O redirection

Hello everyone,I'm reading a book and there's code fragment: exec 3>&1 ls -l 2>&1 >&3 3>&- | grep bad 3>&- exec 3>&- It says that the red part of that code does not close fd 3 but the green does close the fd 3.I can't understand that.....Why?Any predicate will be appreciated.:) (18 Replies)
Discussion started by: homeboy
18 Replies

5. Shell Programming and Scripting

awk output redirection to file

I have a system stat command running which generates data after 5 sec or so. I pass this data to awk and do some calculation to present the data differently. Once done now I want to pass this data to file as and when generated but doesn't work..unless the first command completes successfully.... (6 Replies)
Discussion started by: learnscript
6 Replies

6. Shell Programming and Scripting

Error with redirection in awk

I'm trying to find average of values in 2nd column in some files. Filenames have following pattern eg: tau_2.54_even_v1.xls tau_2.54_odd_v1.xls tau_1.60_v1.xls tau_800_v1.xls #!/bin/bash for file in pmb_mpi tau xhpl mpi_tile_io fftw ; do for f in "2.54" "1.60" "800" ;do if... (2 Replies)
Discussion started by: vishwamitra
2 Replies

7. Shell Programming and Scripting

awk print redirection to variable file name

Hello, i need to redirect the output of print to a variable file name: #This is normal awk '{ print $17 > "output.txt" }' input #I need something like this awk '{ print $17 > "output_${25}.txt" }' input how to format the output file name to contain a variable? (6 Replies)
Discussion started by: nazeeb
6 Replies

8. Shell Programming and Scripting

redirection

Hi, The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale. Now the proble is: How can I redirect stderr to a file? PS: so I want to redirect ALL the errors to a file. I tryed... (9 Replies)
Discussion started by: DNAx86
9 Replies

9. Shell Programming and Scripting

awk two file redirection

Hi, i use awk -F to print three variable delimited by comma $1 $2 $3 if $2=="" i want to extract this information missing from another file using awk -v + some process. but the problem i can't use the two awk together cause of redirection there's a solution. note: i can't use another... (1 Reply)
Discussion started by: kamel.seg
1 Replies

10. Shell Programming and Scripting

Tail -f, awk and redirection

I want to run tail -f to continuously monitor a log file, outputing a specific field to a second log file. I can get the first portion to work with the following command: tail -f log | awk '{if ($1 == "Rough") print $5}' also: awk '{if ($1 == "Rough") print $5}' <(tail -f log) The... (2 Replies)
Discussion started by: mfajer
2 Replies
Login or Register to Ask a Question