473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

doubts about shell scripting!

89
I am trying to concatenate some 100 files from one directory and writing them into another directory and I want to automate this as follows:

But cat statement inside for loop does not work. But echo statement inside the for loop shows the correct path to the files? Why is it not concatenating files? I am new to shell scripting. Thanks in advance.

Expand|Select|Wrap|Line Numbers
  1. if [ $# -lt 4 ]
  2.         then
  3.            echo Usage: $0 Directory st end lib_name
  4.            exit 1
  5. fi
  6.  
  7. echo $1 $2 $3 $4
  8. mkdir test
  9.  
  10. dir=$1
  11.  
  12. IN=$1
  13. IFS="/"
  14. bar=( $IN )
  15. #echo ${bar[3]}
  16. Name=${bar[3]}
  17.  
  18.  
  19. #contatenating test files
  20. for(( i = $2; i <= $3; i++ ))
  21.         do
  22.                echo "$dir/Data/Int/Calls/s_${i}_1_0*qtest.txt"
  23.                 cat $dir/Data/Int/Calls/s_${i}_1_0*test.txt > $4/$Name.txt
  24.  
  25.         done
  26.  
Nov 23 '10 #1
5 1791
Banfa
9,065 Expert Mod 8TB
If the data does not go to the output file where does it go?

If it doesn't go to the screen it must be going somewhere so if it does not go to your desired output and it doesn't go to the screen that suggests that $4/$Name.txt is not producing the expected result. You should check (echo) what it contains to make sure it is correct.
Nov 23 '10 #2
lilly07
89
Echo statement inside the for loop is correctly printing the file path. But I get to to see theerror like "cat... No file found " three times because the path is broken. How can it happen? How can the path gets broken in the cat statement but not in echo statement. Please clarify. Thanks in advance.

Is there any problem because of line 11 and 12 of my code as I am trying to get the name of the file from directory path. No clue for me :)
Nov 23 '10 #3
Nepomuk
3,112 Expert 2GB
What are the file names, that the cat command has problems with? If there are any special characters (e.g. spaces) in the file name, that may be the problem here. As echo doesn't interpret the file names, just prints them, while cat actually tries to access the file, there might be a small error in or problem with the file name which you just missed.

I see, that in your code you put quotation marks around the name with the echo command, not however with the cat command. Quotation marks would solve the space-problem, so a simple solution may be, to put them around the cat file name too.

Greetings,
Nepomuk
Nov 26 '10 #4
Oralloy
988 Expert 512MB
Lilly07,

You do realize that the filenames you give in lines 22 and 23 are one character different?

In line 22, you call for
qtest.txt
and in line 23 you call for
test.txt
This shouldn't matter because of the preceeding asterisk, however you should be aware.

Also, in line 23, you are using simple output redirection '>', and not output concatenation '>>'.

Good Luck!
Oralloy
Dec 1 '10 #5
what are the extensions of the file??

for eg: if all your files are .txt files try this

cat *.txt>>new.txt

new.txt is your concatenated file.
but make sure that the folder in which you execute your scripts contains the only .txt files which you want to concatenate.


store it any where you want
Feb 2 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Javaman59 | last post by:
Hi all, I'm a Unix guy from way back, who's enjoying learning C# and Windows programming. Overall, it's not such a difficult transition (as long as one keeps an open mind :) ), but there is one...
10
by: A.M | last post by:
Hi, I am having difficulty with shell scripting in Python. I use the following command to run a DOS command and put the return value in a Python variable:
1
by: ravjobs | last post by:
helo my dear friends what mail advantages of shell scripting in oracle pls given detaild inforamtions thanks in advance
0
by: ravjobs | last post by:
helo my dear friends give me main advatages of shell scripting in unix with oracle thanks in advance
14
keyvanrahmadi
by: keyvanrahmadi | last post by:
Sorry if this post is rather long but hopefully you wont get bored half way through. I have a project in hand which i have started and have a deadline of 1 week. Basically what i need to do is to...
4
by: sandhya rani | last post by:
like sh command wht r the commands exist to run shell scripting from commamnd prompt ??
1
by: rasmidas | last post by:
Hi, Could anyone please let me know what does it mean by the following statement in solaris shell scripting. $PROMPT " Select an option: " read ans db_option=${ans:=0} I...
7
by: ajd335 | last post by:
Hi all, I am a newbie in shell scripting.. I am writing a code to automate the installation of some softwares. It includes some of the question during installation where we need to choose from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.