Re: Long command lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Re: Long command lines
# 1  
Old 05-22-2002
Question Re: Long command lines

Hello,

AIM: Need to test for the presence of some files (*.F) in a certain directory.

having a problem with this line is ksh:

if test `ls $SOMEDIR/dir/*.F \
2>/dev/null|wc -w` -eq 0

Basically testing for the presence of *.F files in the specified directory. If the return code from 'wc -w' is equal to 0 then no *.F exist

BUT, ls can fail if the command line is too long.
Fails with ..
sh-42 sh: arg list too long.

Could use the find command:

find $SOMEDIR/dir/*.F

along with the word count stuff, but then find is recursive and searches lower subdirectories (which I dont want). I cant find a command / option to use with 'find' to force it to only search that dir.
Any idea

Thanks in advance
E.
# 2  
Old 05-22-2002
The option "-level 0" should limit it to the one directory
# 3  
Old 05-22-2002
But few versions of find have that -level 0 option.

I would do:
cd somedir
ls | grep \\.F\$ | wc -l
to get a count of the *.F files. Then just compare that number to zero.
# 4  
Old 05-22-2002
Sorry didn't know that. I'm only used to SCO.
# 5  
Old 05-22-2002
find will work...

You can use find if you use the -prune and/or -only options for find. I see prune is in the UNIX Nutshell book, but the -only option may not be available in some OSs.

They can help you limit your search parameters and prevent recursive directory searches.

if `find . -name "*.F" -prune -only 2>/dev/null |wc -l` -eq 0

This will only search the current direcory and give your comparison.


Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break one long string into multiple fixed length lines

This is actually a KSH under Unix System Services (Z/OS), but hoping I can get a standard AIX/KSH solution to work... I have a very large, single line file in Windows, that we download via FTP, with the "SITE WRAP" option, into a Z/OS file with an LRECL of 200. This essentially breaks the single... (4 Replies)
Discussion started by: bubbawuzhere
4 Replies

2. UNIX for Dummies Questions & Answers

sed and awk for long lines

Hi, I'm trying make a variable length file to a fixed length of 4000. I'm to pad spaces on the right of a record if length is less than 4000 to make the record length 4000. I'm trying to use the below commands awk '{printf "%-4000s\n", $0}' inputfile.dat > outputfile.dat sed -e :a... (12 Replies)
Discussion started by: uxusr
12 Replies

3. UNIX for Dummies Questions & Answers

Bash does not wrap long lines correctly

Ksh is my default shell, but I want use the bash shell since its convenient to me. When I type a long command line in a terminal, it does not wrap to the next line when I reach the end of the line and it wraps onto the same line, overwriting my prompt and the rest of what I typed. $... (5 Replies)
Discussion started by: senthil.ak
5 Replies

4. Shell Programming and Scripting

Long line displayed as multiple lines in Outlook. Please help!

When a file generated by a shell script is sent as a mail (not as an attachment), in MS Outlook, single lines of the file are displayed as two/three lines (as the lines are long). Is there a way to make each line to be displayed in 'single line with scroll bar' to enable viewing of the long line? (2 Replies)
Discussion started by: thulasidharan2k
2 Replies

5. Shell Programming and Scripting

Long line displayed as multiple lines in Outlook. Please help!

When a file generated by a shell script is sent as a mail (not an attachment), in MS Outlook, single lines of the file are displayed as two/three lines (as the lines are long). Is there a way to make each line to be displayed in 'single line with scroll bar' to enable viewing of the long line? ... (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

6. Shell Programming and Scripting

Pull specific lines from long file based on formula

For people who want to pull a number of lines from a long file using a specific formula n (number of iterations in a loop) a (offset number) b (stretch factor) example with n {1..100} for (( n=1; n<101; n++ )); do awk -v n=$n 'NR==a+(b*n)' a=0 b=1 inputfile >>outputfile (2 Replies)
Discussion started by: sgruenwald
2 Replies

7. Shell Programming and Scripting

Long lines in test.awk

I have a awk script called test.awk which I run using awk -f test.awk file1.txt > file2.txt I am doing a long print statement and want to put it in separate lines Do I need a '/' at the end or not????? Should it be like this print... (12 Replies)
Discussion started by: kristinu
12 Replies

8. Shell Programming and Scripting

splitting long string into several lines?

I'm using a barcode scanner to grab ISBNs. Unfortunately, short of hitting "enter" each time (not easy while on a ladder), there's no good way to split it up. So I scanned it into a series of long lines in notepad. Now, I need to split each line into 12-number lines. instead of:... (4 Replies)
Discussion started by: mbourgon
4 Replies

9. UNIX for Dummies Questions & Answers

Lines too long error

Hi Gurus, I have a big file having around 5000 lines. What I need to do is as below. $cat myfile aaaa bbbb ccc ddd ... I want the output to be as below: 'aaaa,'bbbb','cccc'.... For this I have written something like this code: vi sac.txt |nawk '{printf NR","}'>ss code: (2 Replies)
Discussion started by: thana
2 Replies

10. UNIX for Dummies Questions & Answers

removing lines in a too long file

HI, i need to remove about a 3000000 lines in a "too long file", without using vi editor. Im using hp-ux 11.0. (4 Replies)
Discussion started by: Goodfella
4 Replies
Login or Register to Ask a Question