Hello all!
I am new to unix scripting and I am trying to learn a few things by writing in unix scripts utility programs I wrote in other languages. Here is where I am currently stumped:
I would like to delete files older than "X" generations. By that I mean if in a given directory there are 10...
Hi all,
This newbie needs some help. I've been playing with AWK and SED and am trying to figure out how to replace all non-printable characters with a "."
Actually, can someone tell me how in AWK or SED, I can replace any ASCII characters in the range of 0 - 31 (x0 - x1F), but not the line feed...
Hi all,
I am a bit stuck here with a seemingly simple process: How do I split a file of say X records into n files each file having X/n records?
So if I have a 30,000 record file, how can I split the file into 3 files with each file containing 10,000 records?
Thanks for helping out the newbie...
Hello everyone,
When i try to download a file from a server to my laptop via AFP (Apple File Protocol over TCP/IP), the file transfer is unbearably SLOW. Transferring a 1 meg file takes about 2 mins (that's way too slow). However, uploading the same file to the server takes about the time to...
Hi CaKiwi,
here's my program. Don't know why it prints to STDOUT
awk -f Program.awk dataFile.txt
# ========= program1.awk ==========
outfile = substr($0,9,18)
gsub(/ /,"",outfile)
{print >>outfile ; close(outfile)}
The only way to not get printout on my screen is to redirect STNDOUT...
CaKiwi,
{print >>$1) works fine, it writes to the appropriate file, but it also prints to STDOUT (screen). How can I suppress screen printout?
Thanks!
--Bondster!!
Okay, thanks CaKiwi and Baraka, I got it to work :-)
However, in the general sense, my question still lingers. If I wanted to search records of a file, but limiting my search within specific column locations, how would I do it. I am thinking perhaps the function "substr" might do it...
Hi all,
how can I match using fixed locations. It seems like AWK allows pattern matching, but I need to match in a fixed position. Ex:
FileA.txt contains:
aaaaJobCode bbbbb
aaaaJobControlbbbbb
aaaaJobStatus ccccc
eeeeJob dddddd
If I want only those records that match "Job...
Hey everyone,
newbie #1 still learning awk. I need some help: I have a file, each record contains data and a filename. I want my awk program to append each record to a file whose file name is on that records. For example, if file FILE_A.txt contains:
filename_1.txt data data data
filename_1.txt...
Okay, after some experimenting I got it to work!
It had to do with a subtle change:
Instead of:
A=`awk '/""$B""/{ print $3 } inFile.txt`
I used:
A=`awk '/'"$B"'/{ print $3 } inFile.txt`
Can someone explain why this works?
Thanks!!
--Bondster!!
Ed,
thank you for your prompt response. I tried the double quotes but didn't have much luck. I also tried the link you posted but it just took me back to the tek-tips home page.
Any other suggestions would be greatly appreciated!!
--Bondster!!
P.S. Here is what I am trying to do (with your...
Hi everyone,
after some time, I need to revisit this problem.
The suggested solution:
A=`awk'/HELLO/{ print $3 } inFile.txt`
does a fine job of storing the text "b001.txt" in variable A
However, suppose instead of hardcoding "HELLO", I wish to use a variable, say $B followed...
Hi all,
what's the best way to drop n characters from each record in a given file? The n characters are consecutive, but they could be at the beginning, middle, or end of the record.
For example, given file A.txt which has a record length of 1000, how can I get make file B.txt which has a...
Hey thanks Jamisar,
I think your simple example clarified the rules behind quoting. Geez, I wish the book I was reading used similar examples. Anyway, I changed my script and it worked well.
I'll probably wind up asking for help again in the near future, but I figure with all this practice, It...
Oops! Forgot the "=" in after parm. It should read:
PARM='-v fna='"$DIR/$FILE_1"' -f program.awk'
It still doesn't work though :-(
--Bondster
Hi everyone,
I can't seem to get shell quoting correct in a unix script.
I tried this command in the command line, and it works great:
awk -v file="input1.dat" -f program.awk input2.dat > output.dat
but i can't seem to make it work in a script--I've tried a few quoting combination...
Hey CaWiki,
thanks for the explanation. So does this mean that the expression in a[] have to evaluate to consecutive characters in the record?
Suppose I wanted to do my file comparison based on not just column locations 32-49, but instead, locations 32-38, 41, 47, 49.
How to do??
--Bondster...
By the way, can you walk me through your code? I get the jist of the whole thing, but not at a line-by-line level. In your dif.awk script, I see that you loop through the entire fna file (in my case, my A.txt file) and limit your comparison in the desired column locations (via substr($0,32,18))...
Ugh!!! Silly Silly foolish me!!!
CaWiki, thanks for all your good help--I found out what was wrong. Your code was impeccable--I was at fault.
Here's what I did wrong: I wrote the dif.awk program using Apple's TextEdit program (which of course, adds RTF control characters). When I examined the...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.