cat in the command line doesn't match cat in the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat in the command line doesn't match cat in the script
# 15  
Old 01-27-2009
Hey Nixnoob,

it's not working.
And you're not supposed to put -u and -d at the same time, it's sort of a rule.

and I tried everything you said...

more didn't work, but what's the difference between more and cat?

btw, before I replaced the cat with the more:

sort -n -r -k2 -k1 file1 | uniq -u -d > file2
cat file2

It didn't print out anything, as if file2 was empty...
# 16  
Old 01-27-2009
Quote:
Originally Posted by shira
Hey Nixnoob,

it's not working.
And you're not supposed to put -u and -d at the same time, it's sort of a rule.
Yeah, it's not supposed to even be necessary...-u and -d are the defaults if you just execute uniq.



Quote:
more didn't work, but what's the difference between more and cat?

It didn't print out anything, as if file2 was empty...
More just prints the output 1 page at a time where cat prints every thing to the output at once. I was thinking maybe cat was doing something it shouldn't be...it was just a random thought.

If you do an ls -la on file2 it will probably show the size as zero...that means the command errored and didn't actually create a readable file.

Now I'm just puzzled...I tried your original script and my way on a newly imaged HP-UX 11.23 server and I got the exact output I wanted.


*EDIT* Shira, as System Shock suggests, could you post the entire script as it is on your system?

Last edited by nixnoob; 01-27-2009 at 05:50 PM..
# 17  
Old 01-27-2009
This thread is going to go on forever with everyone trying to guess what's wrong until someone somehow hits it by chance. As shown in my last post, the syntax works.

My last suggestion is to post the entire script here and the location of all files including paths.

Happy hunting... I'm out.
# 18  
Old 01-27-2009
OK, I fixed it!

It wasn't a syntax problem.

This is what I did:
I have a main script which creates a file. This file needs to create another file which is being "built" in a secondary script.

What I did, is that I wrote the "cat" part in the secondary script, and it didn't work, because the file was still in the making process.

Of course that I needed to cat, sort and uniq the file in the main script, and over there to create "temp" which is my final output file.
This is why the cat command worked so well in the command line - because it printed out "temp" after all the process, whilst the cat command in the secondary script printed "temp" in the middle of the making.

I thank you both for your patience - System_Shock, you were really close! Smilie, and nixnoob - you're awfully nice, I'm sorry I puzzled you.
Joey - I'm sorry I puzzled you as well.

The IOU coffee table:
--------------------------
Joey | 2
--------------------------
System_Shock | 1
--------------------------
nixnoob | 1
--------------------------

Shira. Smilie
# 19  
Old 01-28-2009
Way to go girl...figuring it out on your own makes it a lot sweeter in the end.

Smilie Smilie Smilie Smilie Smilie
# 20  
Old 01-28-2009
Quote:
Originally Posted by shira
Hello,

So I sorted my file as I was supposed to:

Code:
sort -n -r -k 2 -k 1 file1 | uniq > file2


You don't need uniq as well as sort; use the -u option:

Code:
sort -u -n -r -k 2 -k 1 file1 > file2

Quote:
and when I wrote
Code:
> cat file2

in the command line, I got what I was expecting, but in the script itself

Code:
 
...
sort -n -r -k 2 -k 1 averages | uniq > temp
cat file2

It wrote a whole different thing, why is that?

Perhaps because you sorted a different file?

You sent the ouput to temp, but you printed file2.
# 21  
Old 01-28-2009
Hi cfajohnson,

it was a typo, I cleared it out in the beginning of thread.
Anyway, I already fixed that problem, I blamed cat for nothing.
The problem was that I should've written this segment in my main script, instead of the secondary script.

Thanks for the help though! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script: "mkdir -p" doesn't work with var(cat x)

Hello, :) I've an issue with the creation of a directory, All work without it :mad: So, below, my scripts with the debug output : #!/bin/bash # PATHS HOME_BACKUP="/home/backup" HOME_SCRIPT="/home/scripts/test/backup_server" TARGET="/var/www" # DATE DATE_Ymd=$(date +%Y-%m-%d) #... (1 Reply)
Discussion started by: Arnaudh78
1 Replies

2. UNIX for Beginners Questions & Answers

Cat command does not respect new line

Here's my script echo "1" >>hello.txt echo "2" >>hello.txt echo "3" >>hello.txt mailx -s "Check Status" #myteam@mycomp.com<hello.txt In Outlook I see EMail body as when I want it to be can you please suggest ? (29 Replies)
Discussion started by: mohtashims
29 Replies

3. AIX

Script to cat and dd last line!!! of each file

hi Guys, Am new to this awesome forum, and yea i need some help here asap thnx :) i have a directory with over 34000 text files, i need a script that will delete the last line of each of this file without me necessary opening the files. illustration:- file1 200 records file2 130 records... (5 Replies)
Discussion started by: eetang
5 Replies

4. Shell Programming and Scripting

for loop with whole line using cat

Hi all, I need to create loop script to read full line and append a variable to each line. cat file I need the output like below 10.0.0.1,136 1 24 048800 id N4 No_Light 10.0.0.1,137 1 25 048900 id N4 No_Light 10.0.0.1,140 1 28 048c00 id N4 No_Light 10.0.0.1,262 1 38 048e80... (13 Replies)
Discussion started by: ranjancom2000
13 Replies

5. Shell Programming and Scripting

Using cat to match pattern start with particular date.

Hi All, version :- SunOS rdrsu1 5.10 Generic_142900-12 sun4u sparc SUNW,SPARC-Enterprise I have a requirenemet, where I have to extrace eroror start with ORA-, which match a perticular date. In below text I only extract out error coming on wed-8 and start with text like "ORA-". hope you... (4 Replies)
Discussion started by: alok.behria
4 Replies

6. Shell Programming and Scripting

cat file1 read line-per-line then grep -A 15 lines down in fileb

STEP 1 # Set variable FILE=/tmp/mainfile SEARCHFILE =/tmp/searchfile # THIS IS THE MAIN FILE. cat /tmp/mainfile Interface Ethernet0/0 "outside", is up, line protocol is up Hardware is i82546GB rev03, BW 100 Mbps Full-Duplex(Full-duplex), 100 Mbps(100 Mbps) MAC address... (6 Replies)
Discussion started by: irongeekio
6 Replies

7. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

8. Shell Programming and Scripting

Cat'ing a multiple line file to one line

I am writing a script that is running a loop on one file to obtain records from another file. Using egrep, I am finding matching records in file b, then outputing feilds of both into another file. **************************** filea=this.txt fileb=that.txt cat $filea | while read line do... (1 Reply)
Discussion started by: djsal
1 Replies

9. UNIX for Dummies Questions & Answers

using 'cat' to in 'while read line'

Hi, I'm having some trouble reading a file that was 'cat' through a while loop. Can anyone suggest alternatives? what i do is cat filename|grep *.stuff while read line do echo $line ... and other commands done The cat,grep line seems to work correctly, but the script hangs when i add in... (3 Replies)
Discussion started by: chugger06
3 Replies
Login or Register to Ask a Question