- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: unix script to create tar file
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
09-29-2003 04:52 PM
09-29-2003 04:52 PM
I have more than 50 files in one directory what I want is to separate the files depending on the first 5 letters (ex. tcpco*, nwint*, voice*..etc).
there is possibilty that few more files with different first 5 letters can be added to this directory.
what i want is the script that will check the first 5 letters and tar them (ex. - all files starting with tcpco* to tcp.tar and so on)
since new files with different names can also be added so I dont want to use
(tar xvf ./tcpco*), how can i use the command in script so I dont have to worry about the new files as well, so script will check the filenames (i.e. tcpco*, voice*....) and tar them individually.
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 05:12 PM
09-29-2003 05:12 PM
Re: unix script to create tar file
ls -1 > file.temp
Thats ls dash 1 to create a alphabetized file list.
# Then
while read -r xx
do
test=substr(5,1)$xx #This you'll have to get to work yourself.
if [ "$test != "$test2" ]
then
tar cfv $test.tar $test*
$test2=$test
fi
test2=$test
done < file.temp
I know its not everything, but its the best I can do right now. Its been a long,long day.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 05:14 PM
09-29-2003 05:14 PM
Re: unix script to create tar file
#!/bin/sh
DONE="none"
for i in `ls`
do
PREFIX=`expr $i : "\(.....\).*"`
if [ $PREFIX != $DONE ]
then
tar cvf $PREFIX.tar $PREFIX*
DONE=$PREFIX
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 05:27 PM
09-29-2003 05:27 PM
Solutionfor i in `ll test| awk '{print $NF}' | cut -c 1-5 | sort -u`
do
tar -cvf $i.tar test/$i*
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 05:34 PM
09-29-2003 05:34 PM
Re: unix script to create tar file
SEP,
I can tell it's been a long, long day for you, you were posting here when I went to bed!
Bhuveneswari,
I think it's only fair to include a bit of a test to stop the script creating the same tar file each time the same five characters come up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 07:37 PM
09-29-2003 07:37 PM
Re: unix script to create tar file
The catch is that, I had included sort -u in the command, and hence only one instance of the five characters will come. So, the condition "each time, the same five charactiers coming up" will not come in to picture.
I guess sort -u will take care of this, feel free to correct me if I am wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2003 07:42 PM
09-29-2003 07:42 PM
Re: unix script to create tar file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2003 07:39 PM
09-30-2003 07:39 PM
Re: unix script to create tar file
btw, is the owner's question answered or not???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2003 05:15 PM
10-01-2003 05:15 PM