Including case insensitivity into loop command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Including case insensitivity into loop command
# 1  
Old 09-02-2009
Including case insensitivity into loop command

I have the following piece of code:
Code:
for file in *csv; do cat $file >> $newfile; done
for file in *CSV; do cat $file >> $newfile; done

and would like to know how to combine these two rules into one? The combined rule would then include the case insensitivity that I am looking for.
# 2  
Old 09-02-2009
Quote:
Originally Posted by figaro
Code:
for file in *csv [...]
for file in *CSV [...]

One way:

Code:
for file in *csv *CSV [...]

# 3  
Old 09-02-2009
That is great, thanks.
# 4  
Old 09-02-2009
Why run cat dozens of separate times in a shell loop when you could just run it once with no loop at all? concatenating files is what cat is for. Smilie It can of course accept multiple arguments.

Code:
cat *.csv *.CSV >> $newfile

If you're worried about there being too many arguments for commandline parameters to handle, I don't think a loop will help, you'll need to use a pipe.
Code:
# ls -1, as in one, not L
ls -1 | grep -i '\.csv$' | xargs --no-run-if-empty cat >> $newfile


Last edited by Corona688; 09-02-2009 at 01:13 PM..
# 5  
Old 09-02-2009
@Corona688: thank you for your answer, but those specific lines were actually taken from one of the posts on this forum, but your suggestion seems worthwhile and is actually rather quick.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Including Hash / in sed command filter

Hello All, I want to print data in between two lines in a file sample.txt through more or cat command on the screen. For that I am using below sed command to give the BEGIN and END text. Content of sample.txt server01:~ # cat /proc/mdstat Hello this is a text message 1 Hello this is a... (5 Replies)
Discussion started by: Xtreme
5 Replies

2. Shell Programming and Scripting

Case sensitive in If loop .

Hi All, select app from the menu: ABC DEF GHI JKL ALL # ALL will select all the apps in the menu echo "Enter your option" read option; if then <execute the below command> elif # option is the 1 selection from menu...not ALL <execute the below command> else (14 Replies)
Discussion started by: Devaraj A
14 Replies

3. Linux

How to use a case stmt in a for loop?

How can I merge the move statements with the "FOR" loop to do a move of a file right after it zips it and not wait until all of the files are zipped to move all outisde the for loop. Here is my current code: for file in `ls -rt $svdumpdir/* | grep -v '.gz$' | grep '.gtt$' ` do echo... (8 Replies)
Discussion started by: mrn6430
8 Replies

4. Shell Programming and Scripting

Including variable in sort command

I have the following awk statement that computes rank of a column and sorts it based on rank. sort -k6 -n file | awk '$6 != prev { rank = NR }{ print $1, $6, rank ; prev = $6 }' I need the above code to accept variables for the column in the sort statement ("-k6"). Is there a better... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

5. Shell Programming and Scripting

Case loop condition

hello, I would like to do exit at the end ie list all errors before exiting How to put the token exit in a variable with a loop ? Thanks function g1 () { case "$1" in (-0-0 | -0-1 | -0-2 | -0-3 | -1-0 | -1-1 | -1-2 | -1-3) # nothing, OK ! ;; (*) echo 'Fatal, $1 = '"'$1'"', Date... (9 Replies)
Discussion started by: amazigh42
9 Replies

6. Shell Programming and Scripting

Help With Loop in Case Statement script

I am writing a bash script that asks the user for input and I need it to repeat until the user selects quit.. I dont know how to write the loop for it I searched all over but i still do not get it.. if anyone could help with this it would be greatly apprciated here is my script so far: #!... (2 Replies)
Discussion started by: Emin_Em
2 Replies

7. Shell Programming and Scripting

executing/including command in mailx subject line

Hi, Is it possible for me to include the results from a command in the subject line? What I am looking to do is get the file count and include it into the subject line as well as the list of files in the body. Example Subject line: Currently 25 files in directory My Code: #!/bin/ksh cd... (2 Replies)
Discussion started by: ozifer
2 Replies

8. Shell Programming and Scripting

Command to get File Timestamp including seconds [Aix 5.3]

Is there a command (like ls -l) to get the file time stamp including seconds? The ls -l gives only the HH:MM, No SS I don't have a C compiler to call stat() I don't a command like stat too. Please help. (8 Replies)
Discussion started by: firdousamir
8 Replies

9. Shell Programming and Scripting

case loop... repeat on bad input?

I'm trying to get a case statement to start over if an undefined option is selected... But I am ata loss on how to actually do it. Here is a quick example of what I have. Echo "1) do this/n 2) Do that/n 3) Quit/n Make a selection/n" Read answer Case answer in 1) Dothid;; 2) Dothat;;... (3 Replies)
Discussion started by: trey85stang
3 Replies

10. UNIX for Advanced & Expert Users

whats command for search including sub directory ?

What is the command for search the program name from the entire directory (all directories in the unix box, means including sub directories...) (2 Replies)
Discussion started by: gksenthilkumar
2 Replies
Login or Register to Ask a Question