- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: script help, string matching form new 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
Discussions
Discussions
Forums
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
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
тАО08-25-2005 09:19 PM
тАО08-25-2005 09:19 PM
I need a shell script to process several files, they are FileA, FileB, FileC, FileD,...
1.feature of the file
.each have 600 columns
.lines from 2nd line to bottom are useful
.from column 2-10 is P_name, column 60-80 is Description
2.demands
.trim each file to TA, TB, TC, ... formed by first unique P_name lines
.merge TA line to TB if P_name in that line of TA is not in TB, this make file M1, then M2 is between TB and TC, M3 is between TC and TD,...
what I need is M1, M2, M3, ... , could you help me?
Hope I explained well and thank you in advance.
Best regards,
Patrick
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2005 03:07 AM
тАО08-26-2005 03:07 AM
Solutiondo
logfile="T$(echo $file | sed 's/.*\(.\)$/\1/')"
awk '(NR!=1) { for (i=2;i<=20;i++) { print $i; } }' $file | sort -u > $logfile
done
It will create TA, TB, TC files.
You can create M1, M2, M3 files as,
grep -vf TA < TB > M1
like that.
hth.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2005 11:39 PM
тАО08-26-2005 11:39 PM
Re: script help, string matching form new file
Thank you for taking the time.
but the result seems not what I want.
1. I need the whole line, not only the P_name.
2. The script is defined to work on column 2 to 10, but I found in result I got column 165 to 176, I don't know why. Too many columns?
3. How can I start from 4th or 6th line? ( words above are not very correct: ".lines from 2nd line to bottom are useful", because source file varied, I have to change the configure from time to time)
Best regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2005 12:01 AM
тАО08-27-2005 12:01 AM
Re: script help, string matching form new file
1234567890123456789012345678901234567890
testfile1 desc trees
testfile1 desc apple
partnume1 desc orange
testfile1 desc table
partnume2 desc 12345
partnume9 desc na
partnume7 desc na
the result TA should be :
testfile1 desc trees
partnume1 desc orange
partnume2 desc 12345
partnume7 desc na
partnume9 desc na
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2005 02:14 AM
тАО08-27-2005 02:14 AM
Re: script help, string matching form new file
If this problem should not be too complex you need to sort the file using the first field as key (is it any problem).
sort -k 1
then , try awk
cat outfile |awk ' $1 != old { print ; old=$1}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2005 05:28 PM
тАО08-27-2005 05:28 PM
Re: script help, string matching form new file
as in "demands", the P_name is from column 2 to 10, sometimes it contains several blanks, so several fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-27-2005 11:12 PM
тАО08-27-2005 11:12 PM
Re: script help, string matching form new file
One method I have sometimes used is to translate blanks to a caracters, not used as field separators. In your case, a "qiuck and dirty" solution could look something like:
(not sure what you want to do with column 1)
cut -c 1 infile >tmp1
cut -c 2-10 infile >tmp2
cut -c 11- infile >tmp3
tr " " "_"
paste -d " " tmp1 tmp4 tmp2 >tmp5
Now, column 1 and 2-10 should be two field separated by blanks. Blanks in pos 2-10 in the original file is translated to "_".
Now you can try my previous solution (but using $2 instead of $1).
After that you can use the same method as above for translating "-" to blanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2005 12:35 PM
тАО08-28-2005 12:35 PM
Re: script help, string matching form new file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2005 08:32 PM
тАО08-28-2005 08:32 PM
Re: script help, string matching form new file
The attached file gives an better idea about how your files look like.
I assume the first field ia always a blank so we can ignore it (it is easy to recreate in the final file if you want).
I also assume there is one or more blanks in pos 11- .
I am also afraid that we must sort the file if it should be possible to solve without using a full database tool. Is it OK ?
In the following ex. you should type a blank instead of
Try the following on one of your files.
cut -c 2-10 infile >tmp1
cut -c 11- infile >tmp2
tr "
paste -d"\0" tmp3 tmp2 >tmp4
sort -k 1 tmp4 >tmp5
awk ' $1 != old { print ; old=$1}' |tr "_" "
Does the output look like what you want in the TA file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2005 11:36 PM
тАО08-28-2005 11:36 PM
Re: script help, string matching form new file
#!/bin/ksh
# Enter user input
LINESTART=2
for file in `ls FILE*`
do
logfile="T$(echo $file | sed 's/.*\(.\)$/\1/')"
for lno in `awk -v ln=$LINESTART '(NR!=ln) { print NR,$1 }' ${file} | sort -uk 2,20 | cut -d" " -f1 | sort`
do
sed -e "$lno!d" $file > $logfile
done
done
## Change LINESTART to specify from 2nd line to last or 6th line to last line.
hth.