- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script help: divide one file to several and na...
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
03-07-2004 08:12 PM
03-07-2004 08:12 PM
I have a long one line text file. To simplize it I made a sample fileA, following is its content,
ABC+12345678P1P90+DEF+12345678P2P90+def+12345678P3P90+JKL+12345678P4P90+MNO+12345678P5P90+.......
I want to seperate it to several files using such rule,
1. when match texts in the set {ABC, DEF,def,JKL,MNO}, (case sensitive), create a new file with the match charactors and its following.
2. name the file with 13th-15th charactor(C13,C14,C15) counted from the matching point.
the output should like following files,
fileA_P1P:
ABC+12345678P1P90+
fileA_P2P:
DEF+12345678P2P90+
fileA_P3P:
def+12345678P3P90+
fileA_P4P:
JKL+12345678P4P90+
fileA_P5P:
MNO+12345678P5P90+
Hope I've written my mind. Many thanks for any help.
Patrick
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2004 08:48 PM
03-07-2004 08:48 PM
Re: Script help: divide one file to several and named the new file with pattern in original file
OLDIFS=$IFS
export IFS=+
xx=$(cat $1)
set $(echo $xx)
export IFS=$OLDIFS
set $(echo $1)
let params=${#@}
while [ "$params" -ge "2" ]
do
name=$(echo $1"+"$2"+"|cut -f2 -d"P")
echo $1"+"$2"+" > "fileA_P"$name"P"
shift 2
let params=$params-2
done
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 06:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:28 AM
03-08-2004 07:28 AM
Re: Script help: divide one file to several and named the new file with pattern in original file
Try this one line perl script...
perl -ne '$x=~s/((ABC|DEF|def|JKL|MNO))/\t$1/g;@a=split("\\t",$x);do { $b=substr($_,12,3); system("echo $_ >fileA_$b") if $b; } for (@a);' theonelinefile
This assumes their are no "tab" characters in the string.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2004 07:33 AM
03-08-2004 07:33 AM
Re: Script help: divide one file to several and named the new file with pattern in original file
perl -ne 's/((ABC|DEF|def|JKL|MNO))/\t$1/g;@a=split("\\t",$_);do { $b=substr($_,12,3); system("echo $_ >fileA_$b") if $b; } for (@a);' theonelinefile
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2004 10:56 AM
03-09-2004 10:56 AM
Re: Script help: divide one file to several and named the new file with pattern in original file
Hi, John, your script is the solution. The only small bug is a file named fileA_ was created besides fileA_P1P to fileA_P5P.
The content of fileA_ is :
MNO++
Best regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2005 09:31 PM
08-25-2005 09:31 PM