- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script use to combine several files into...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 12:10 AM
01-14-2003 12:10 AM
Shell script use to combine several files into one files
I want to combine serveral text files into one textfiles. e.g.
Severals Files in a directory:
AAA00001
AAA00002
AAA00003
AAA00004
BDD00001
BDD00002
BDD00003
BDD00004
BDD00005
.....
...
..
These files will be combined into:
AAA00000
BDD00000
....
..
.
Where the content of AAA00000 equal to the combination of AAA00001, AAA00002, AAA00003, AAA00004.
Pls advise
Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 12:31 AM
01-14-2003 12:31 AM
Re: Shell script use to combine several files into one files
while read fname
do
cat ${fname}* >${fname}00000
done
something like that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 12:35 AM
01-14-2003 12:35 AM
Re: Shell script use to combine several files into one files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 01:09 AM
01-14-2003 01:09 AM
Re: Shell script use to combine several files into one files
If I need to count back from the last position, say, 00001 and do a cut there.
The remain text become AAA .
How can I do .?
Thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 03:00 AM
01-14-2003 03:00 AM
Re: Shell script use to combine several files into one files
Try this:
for i in $(ls | cut -c1-3)
do
cat ${i}* >> ${i}00000
done
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 03:13 AM
01-14-2003 03:13 AM
Re: Shell script use to combine several files into one files
Sorry one correction:
for i in $(ls | cut -c1-3 | sort -u)
do
cat ${i}* >> ${i}00000
done
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 07:58 AM
01-14-2003 07:58 AM
Re: Shell script use to combine several files into one files
I should say that:
"AAA" is the prefix of the filename. However, it is a randomly prefix pattern. So, say, it may be Dedss00001, Dedss00002.....etc., KKKAA00001, KKKAA00002...etc...
Because many many files with different length there and I may not be possible to use " cut -c1-3 " apply to all of the files. So, how can I do so that the script can find how long of the prefix ?
that is, cut -cx-y , where y is the last position of the filename and x is the 6th counting from the last position y.
Thanks ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:13 AM
01-14-2003 08:13 AM
Re: Shell script use to combine several files into one files
ls -1 *[0-9][0-9][0-9][0-9][0-9][0-9] | awk ' { print " cat" ,substr($1,1,length($1-6)) "[0-9][0-9][0-9][0-9][0-9][0-9] > " substr($1,1,length($1-6)) "0" }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:17 AM
01-14-2003 08:17 AM
Re: Shell script use to combine several files into one files
This is the solution if the last part is always six characters:
for i in $(ls | sed 's/......$//' | sort -u)
do
cat ${i}* >> ${i}00000
done
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:20 AM
01-14-2003 08:20 AM
Re: Shell script use to combine several files into one files
ls -1 *[0-9][0-9][0-9][0-9][0-9][0-9] | awk ' { print " cat" ,substr($1,1,length($1-6)) "[0-9][0-9][0-9][0-9][0-9][0-9] > " substr($1,1,length($1-6)) "0" }'
| sort -u > file_command
sh file_command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:22 AM
01-14-2003 08:22 AM
Re: Shell script use to combine several files into one files
Given a filename you can use the shell's parameter substitution to get the basename and the length of that token.
Given:
# NAME=/var/tmp/filename
# BN=${F##*/}
# echo $BN
#...returns "filename" or the 'basename'
# L=${#BN}
# echo $L
#...returns the length or here, eight (8)...
Regards!
...JRF...
L=${#F} will
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:42 AM
01-14-2003 08:42 AM
Re: Shell script use to combine several files into one files
Fix your OLD suffix (one of the current files ie 000001) and NEW suffix (ie 000000) and try this one :
#!/usr/bin/sh
OLDSUF=001
NEWSUF=000
for var in *$OLDSUF
do
PREF=$(echo $var | sed 's/'$OLDSUF'$//')
cat ${PREF}* > ${PREF}${NEWSUF}
done
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:50 AM
01-14-2003 08:50 AM
Re: Shell script use to combine several files into one files
unchecked, untested. If taking this to production, add tests to the open calls.
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:50 AM
01-14-2003 08:50 AM
Re: Shell script use to combine several files into one files
unchecked, untested. If taking this to production, add tests to the open calls.
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 08:51 AM
01-14-2003 08:51 AM
Re: Shell script use to combine several files into one files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 09:22 AM
01-14-2003 09:22 AM
Re: Shell script use to combine several files into one files
HTH
-- Rod Hills
open(LIS,"ls -1|");
$prv=""
while(
chomp;
$fil=$_;
next if substr($fil,3,5) eq "00000" ;# ignore result file
$cur=substr($fil,0,3);
if ($prv ne $cur) {
close OUT if $prv;
open(OUT,">${cur}00000");
$prv=$cur;
}
open(INP,"<$fil");
while(
close INP;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 11:35 AM
01-14-2003 11:35 AM
Re: Shell script use to combine several files into one files
# perl -e'local$/;for(<* >){/^([A-Z]+)(\d+)$/i or next;$2>0 or next;open$x,"<$_";open$y,">>${1}00000";print$y <$x>}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2003 06:24 PM
01-14-2003 06:24 PM
Re: Shell script use to combine several files into one files
I did the script by reference your examples. Here:
for i in (`ls -1 *[0-9][0-9][0-9][0-9][0-9][0-9]|sort -u)
do
cat ${i}* >> ${i}00000
done
Happy scripting!