Different results from awk, sed, tr in different directories???


 
Thread Tools Search this Thread
Operating Systems HP-UX Different results from awk, sed, tr in different directories???
# 1  
Old 02-22-2007
Different results from awk, sed, tr in different directories???

I cannot explain why it gives different results when I try the awk, sed, tr command combination with the same input.
(aondufd1)psoftfs:/aon/dev/psoft/FSTST88/autosys>echo ${MailFile}
+ echo mfint003pr.in1*
mfint003pr.in1*
(aondufd1)psoftfs:/aon/dev/psoft/FSTST88/autosys/scripts>echo ${MailFile} | awk -F. '{ print $1 "." }' | sed 's/.*\(...\)\..*/\1/' | tr [A-Z] [a-z] | tr -d [0-9]
+ echo mfint003pr.in1*
+ awk -F. { print $1 "." }
+ sed s/.*\(...\)\..*/\1/
+ tr -d 1
+ tr [A-Z] a
3pr
(aondufd1)psoftfs:/aon/dev/psoft/FSTST88/autosys/scripts>cd ../parm
+ cd ../parm
(aondufd1)psoftfs:/aon/dev/psoft/FSTST88/autosys/parm>echo ${MailFile} | awk -F. '{ print $1 "." }' | sed 's/.*\(...\)\..*/\1/' | tr [A-Z] [a-z] | tr -d [0-9]
+ echo mfint003pr.in1*
+ awk -F. { print $1 "." }
+ sed s/.*\(...\)\..*/\1/
+ tr -d [0-9]
+ tr [A-Z] [a-z]
pr
One big question mark in my head right now. Could someone please help. Thanks.
There were no additional profiles loaded when changing directories. just doing the cd command.
The output should be 3pr. That would be the correct one, right?
# 2  
Old 02-22-2007
You have a file named "1" in the first directory and you are not quoting the arguments to tr, so "[0-9]" is expanded by the shell to "1".
# 3  
Old 02-23-2007
that is genius! yup I have file named 1 in the first directory. Yes, that is our resolution, to put double quotes for "[0-9]" and to "[A-Z]" "[a-z]". Just a stupid question:
1. How does tr read the file named 1, but I know the tr only accepts strings and characters. I tried to create a file named 3, and it accepts the 1 and 3 files and went to syntax error. how does it happens?
(aondufd1)acking:/aon/dev/psoft/FSTST88/autosys/parm>echo ${MailFile} | awk -F. '{ print $1 "." }' | sed 's/.*\(...\)\..*/>
+ echo mfint003pr.in1*
+ awk -F. { print $1 "." }
+ sed s/.*\(...\)\..*/\1/
+ tr -d 2 3
+ tr [A-Z] [a-z]
tr: The combination of options and String parameters is not legal.
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
tr [ -cd | -cs | -d | -s ] [-A] String1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Large search replace using sed results in memory problem.

I have one big file of size 9GB (big_file.txt). This big file has sentences and paragraphs like any usual English document. I have another file consisting of replacement strings for sed to use. The file name is replace.sed and each entry in one line looks like this: s/\<shout\>/shout/g s/\<b is... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

2. Shell Programming and Scripting

Narrowing sed Results in While Loop

find $SRC -type f -name *.emlx | while read FILE do if : then sed -n '/From/p' $FILE fi done > $DEST-output.txt The loop above spits out a .txt file with several lines that look like this: From: John Smith <jsmith@company.com> How can I narrow that sed result to spit out the email... (5 Replies)
Discussion started by: sudo
5 Replies

3. Shell Programming and Scripting

sed Unexpected results, missing first search item

I created 3 files with the identical data as follows dial-peer voice 9999 pots trunkgroup CO list outgoing Local translation-profile outgoing LOCAL-7-DIGITS-NO-PREPEND-97 preference 2 shutdown destination-pattern 9......$ forward-digits 7 dial-peer voice 10000 pots ... (6 Replies)
Discussion started by: popeye
6 Replies

4. Shell Programming and Scripting

Unexpected results with lists in GNU sed

I have been living with this problem with GNU sed v4.1.4 for a long time, but now I really need to figure it out. When using a list in either an address or a search, the expression is matching lower and upper-case letters. works as it should. For example, if I run sed -nr "// p"... (7 Replies)
Discussion started by: nctrader
7 Replies

5. Shell Programming and Scripting

sed returns different results while substitution on a pipe delimited file

Hi, Need help with a sed command that I am using to substitute 3 positions of a pipe delimited file. i am getting different results while substituting the same position of two different files with the same value. Please see details below: $ cat chk2 ... (3 Replies)
Discussion started by: vmenon
3 Replies

6. Shell Programming and Scripting

How to print sed results

Dear all, How can I print results (and of course, send this result to the text file) of sed command. I mean, I want to know which lines of which files sed command has found. For e.g, the result text file should contains: file1.c:line 12 file2.h:line 14 file2.h:line 37 Please help me (10 Replies)
Discussion started by: Hannibal2010
10 Replies

7. Shell Programming and Scripting

Sed in vi - \r and \n not giving desired results

I use many different machines at work, each with different versions of o/s's and installed applications. Sed in vi is particularly inconvenient in the sense that sometimes it will accept the "\r" as a carriage return, sometimes not. Same thing with "\n". For instance, if I have a list of hosts... (7 Replies)
Discussion started by: MaindotC
7 Replies

8. Shell Programming and Scripting

PERL - traverse sub directories and get test case results

Hello, I need help in creating a PERL script for parsing test result files to get the results (pass or fail). Each test case execution generates a directory with few files among which we are interested in .result file. Lets say Testing is home directory. If i executed 2 test cases. It will... (4 Replies)
Discussion started by: ravi.videla
4 Replies

9. UNIX for Dummies Questions & Answers

tar, zip multiple separate directories and move the results to another volume

TIA, I'm using FreeBSD 6 I have a series of Directories (A,B,C,...Z). Each directory has files and other directories within it. I want to compress the contents of each top directory into a single file so that I get an archive of each directory (for example, A.gzip) AND and want to move... (5 Replies)
Discussion started by: jccbin
5 Replies

10. Shell Programming and Scripting

need a little help with results from awk

Hi there all, I am using a line to get some replys from my PS I do ps -ef |awk '{printf $9}' But my result is 1 big line. No spaces between the lines or someting for example:... (2 Replies)
Discussion started by: draco
2 Replies
Login or Register to Ask a Question