Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need a script to concatenate several files in one step, I have 3 header files say file.S, file.X and file.R, I need to concatenate these 3 header files to data files, say file1.S, file1.R, file1.X so that the header file "file.S" will be concatenated to all data files with .S extentions and so on for "file.X" and file.R with the .X and .R data files..
I tried using wild cards, like:
cat file.S file[1-50].S > file[1-50].SP
but I got a message saying that file[1-50].SP does not match
so can this be done through a script? this will save a LOT of time for me, so if someone can help me it will be much appreciated
Location: Argentina, corrientes (far from buenos aires, to the north)
Distribution: Ubuntu :(
Posts: 74
Rep:
mm
Didn't understood very well what you need, a better explanation perhaps with an example of what you want and not what you need would be much better.
Code:
if [ ! -e headers.S ] ; then
touch headers.S
fi
for i in `seq 1 50` ; do
cat file$i.S headers.S >> headers.S.tmp
done
cat headers.S.tmp > headers.S
rm headers.S.tmp
here every file[1-50].S is concatenated to headers.S
I think here you have all you need to make your own version.
But, anyway, my command does a different thing than yours. I'm trying to add headers.S at the beginning of each file$1.S file. Yours gets all files into one big files... Perhaps, the OP should explain the problem in more detail, since we apparently understood it differently.
I want to do what Uncle_Theodore's script does exactly
thanks a lot for both of you, I am a beginner in UNIX, so can you please tell me what is the shell for these 2 scripts?
Sorry, 1 last question, the script works very fine to files ending with the numbers i.e file1.S, file2.S etc...
I tried applying the same script to files having the numbers between the letters of the name like DSQ_SW01_Blk, DSQ_SW02_Blk, etc... but it didn't work
I used the same code but just changed the following:
cat header.S DSQ_SW0$i_Blk > temp
but it didn't work, so how can I implement that correctly?
Location: Argentina, corrientes (far from buenos aires, to the north)
Distribution: Ubuntu :(
Posts: 74
Rep:
mm
Quote:
Originally Posted by docaia
Sorry, 1 last question, the script works very fine to files ending with the numbers i.e file1.S, file2.S etc...
I tried applying the same script to files having the numbers between the letters of the name like DSQ_SW01_Blk, DSQ_SW02_Blk, etc... but it didn't work
I used the same code but just changed the following:
cat header.S DSQ_SW0$i_Blk > temp
but it didn't work, so how can I implement that correctly?
try this:
Code:
cat header.S DSQ_SW0${i}_Blk > temp
bash is interpreting that your variable is $i_Blk and not just $i
example:
bash-3.1# cat prueba.sh1
#!/bin/bash
for i in `seq 1 10`; do
echo header.S DSQ_SW0${i}_Blk
done
everything is working perfect, is there a way to ask the user to enter the first and last file numbers so that the script will work on this range of numbers only instead of editing the script every time?
I used the following code:
i= $1
j= $2
for((i; i<=j))
....and so on
it worked if I enter the script name and 1st and last file numbers, I just want to modify it so that it will ask the user to enter the first file with a message, then it will ask for the last file with another message then works
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.