bash ls command file issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash ls command file issue
# 1  
Old 05-03-2012
bash ls command file issue

Code:
ls -l /md01/EL/MarketData/inbound/ststr/INVENTORY* |tail -5 |awk '{ print $5,$6,$7,$8,$9 }'

If I run the above from the command line the output to md_email is formatted correctly as

Code:
78213497 May 1 12:50 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120430.PINESTREET.CSV.done
77904740 May 2 21:35 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120501.PINESTREET.CSV
77904740 May 2 13:05 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120501.PINESTREET.CSV.done
72218242 May 3 19:50 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120502.PINESTREET.CSV
77839922 May 3 12:50 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120502.PINESTREET.CSV.done

Code:
echo `ls -l ${indir}/${client}/CONTRACT* |tail -5 |awk '{ print $5,$6,$7,$8,$9 }'` >> $md_email

If I execute the above in a redirect to a file using a script the list does not maintain the file position -

Code:
78213497 May 1 12:50 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120430.STATESTREET.CSV.done 77904740 May 2 21:35 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120501.STATESTREET.CSV 77904740 May 2 13:05 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120501.STATESTREET.CSV.done 72218242 May 3 18:33 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120502.STATESTREET.CSV 77839922 May 3 12:50 /md01/EL/MarketData/inbound/ststr/INVENTORY.20120502.STATESTREET.CSV.done

I can't figure out if it's the file 'md_email' causing the issue or the way I am redirecting the command.

Last edited by Scrutinizer; 05-03-2012 at 05:56 PM.. Reason: some more code tags
# 2  
Old 05-03-2012
This is one of the more annoying side effects of useless use of backticks, the flattening of all whitespace into simple spaces.

The echo and the backticks are completely unnecessary here fortunately. You can redirect anything that prints to standard output, not just echo.

Code:
ls -l /md01/EL/MarketData/inbound/ststr/INVENTORY* |tail -5 |awk '{ print $5,$6,$7,$8,$9 }'  >> $md_email

# 3  
Old 05-04-2012
Removing echo and backticks fixed it. I have no idea why I was using echo - totally useless. I read the link provided. Thanks so much.
# 4  
Old 05-04-2012
Code:
echo `ls -l ${indir}/${client}/CONTRACT* |tail -5 |awk '{ print $5,$6,$7,$8,$9 }'\r` >> $md_email


You can try this once .. this may work...

Last edited by Franklin52; 05-05-2012 at 10:42 AM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert subnode in xml file using xmlstarlet or any other bash command?

I have multiple xml files where i want to update a subnode if the subnode project points to different project or insert a subnode if it doesn't exist using a xmlstarlet or any other command that can be used in a bash script. I have been able to update the subnode project if it doesn't point to... (1 Reply)
Discussion started by: Sekhar419
1 Replies

2. UNIX for Beginners Questions & Answers

Bash command to find a file and print contents

I need to find a file and print its contents I am trying but it is not working find -path /opt/app-root/src/.npm/_logs -type f -name "*.log" -print Version $ bash -version GNU bash, version 4.4.12(1)-release (x86_64-pc-msys) (1 Reply)
Discussion started by: SVRao19056
1 Replies

3. Shell Programming and Scripting

Reading from file bash command

Hello, I have a file in the following format id sample platform R1 R2 gene1 gene2 gene3 1 abc llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp asp 2 def llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp 3 ghi llumina ... (3 Replies)
Discussion started by: nans
3 Replies

4. Shell Programming and Scripting

Performance Issue for a file search command

Hi All, This query is regarding performance improvement of a command. I have a list of IDs in a file (say file1 with single ID column) and file2 has the data rows. I need to get the IDs from file1 and search in file2, matching rows from file2 should be written to a file3. For this... (4 Replies)
Discussion started by: Tanu
4 Replies

5. Shell Programming and Scripting

Bash looking in different directory for file that isn't referenced in command

When I run the below bash I get the expected output, which is the sum of all matching targets less than 20 in $file1. The filename in the directory is fixed (in bold). for file1 in /home/cmccabe/Desktop/test/panel/reads/16-0000_EPIL70.txt ; do bname=`basename $file1` ... (3 Replies)
Discussion started by: cmccabe
3 Replies

6. UNIX for Advanced & Expert Users

Issue with rm command in a tera byte file system

We have a production file system which has 6+ million files with more than 1 tera byte in size. When trying to delete selective files through a weekly script files are not deleted. Please advise with ideas. (5 Replies)
Discussion started by: kppublicmail
5 Replies

7. Shell Programming and Scripting

redirect time command output to file (cygwin bash)

I have set up a bash script to run a long list of things that I need to time. I would like to redirect the output of time to a file. I have set it up like, echo "Runtimes for servlet 4, 100K structures" > test_times.txt echo "" >> test_times.txt echo "runs where N=10" >> test_times.txt echo... (7 Replies)
Discussion started by: LMHmedchem
7 Replies

8. Shell Programming and Scripting

syntax issue with quotes in mysql command for a bash script

i'm trying to write a bash script that executes a mysql statement mysql -sN -e INSERT INTO "$database"."$tableprefix"users (var1, var2,var3) VALUES (123, '1','') i don't know where to put the quotes it doesnt work with this one: ` it seems i can only put double quotes around the... (0 Replies)
Discussion started by: vanessafan99
0 Replies

9. HP-UX

Performance issue with 'grep' command for huge file size

I have 2 files; one file (say, details.txt) contains the details of employees and another file (say, emp.txt) has some selected employee names. I am extracting employee details from details.txt by using emp.txt and the corresponding code is: while read line do emp_name=`echo $line` grep -e... (7 Replies)
Discussion started by: arb_1984
7 Replies

10. UNIX for Dummies Questions & Answers

Bash script to delete file input on command line

1) I wrote a script and gave the desired permissions using "chmod 755 scriptname". Now if i edit the script file, why do i need to set the permission again? Didn't i set the permission attribute.. or if i edit the file, does the inode number of file changes? 2) I am running my unix on a server... (1 Reply)
Discussion started by: animesharma
1 Replies
Login or Register to Ask a Question