- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Korn shell programming
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-08-2001 08:16 AM
01-08-2001 08:16 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 08:23 AM
01-08-2001 08:23 AM
Re: Korn shell programming
Here is fine. What is your question?
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 08:27 AM
01-08-2001 08:27 AM
Re: Korn shell programming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 08:39 AM
01-08-2001 08:39 AM
Re: Korn shell programming
i got a file sorted by user name (at the beginning of the line) and i want to split it out or generation other files for each user, fo exemple if my file have 3 lines beginning with Jasmin, 12 lines beginning with Bob and 7 lines with Fred, how i can take those lines out of this file to create new files for each users? I got about 200 users so i want to make a script to do it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 08:45 AM
01-08-2001 08:45 AM
Re: Korn shell programming
'grep' is one way:
# grep -i Jasmin /tmp/input > /tmp/output
The above looks case-insensitively for "Jasmin" in /tmp/input, and writes matching entries to /tmp/output.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 08:53 AM
01-08-2001 08:53 AM
Re: Korn shell programming
Since the matching characters of Jasmin, Bob etc start at the beginning of the lines, if you are looking for precision and omit "Bob" occurring in the middle of the line, you may want to try:
grep "^Bob" LOG > Bob.log
Hope this helps. Regards.
Steven Sim
Brainbench MVP for Unix Admin
http://www.brainbench.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 09:05 AM
01-08-2001 09:05 AM
Re: Korn shell programming
name = $1;
print $0 > name;
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 09:07 AM
01-08-2001 09:07 AM
Solutioncat users_file | sort -u >> users_file1
for i in `cat users_file1`
do
grep $i users_file >> $i.file
done
The first line of the script will do a cat of your data file, sort it, and only give you one entry for each user in user_file1. Then in the next line it takes each users_file1 entry and greps for it in users_file and writes the output to user_name.file. It will do this for every entry in users_file1. Change the file names in the script to reflect whatever the file names you want to use are.
I hope this helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 09:09 AM
01-08-2001 09:09 AM
Re: Korn shell programming
Curtis' answer looks good, except you may want to replace the > with >>, so that you get all the lines. > means overwrite, and >> means append.
Mo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 10:15 AM
01-08-2001 10:15 AM
Re: Korn shell programming
I've already heard that there a command to do that... i might be wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 10:21 AM
01-08-2001 10:21 AM
Re: Korn shell programming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 10:23 AM
01-08-2001 10:23 AM
Re: Korn shell programming
for i in `sort -u the_file | awk '{print $1}'`; do
grep "^$i" the_file >> $i.out
done
Ovidiu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 10:25 AM
01-08-2001 10:25 AM
Re: Korn shell programming
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 11:15 AM
01-08-2001 11:15 AM
Re: Korn shell programming
With regard to your last question about reading and comparing to the previously read line; 'awk' scripts can do this.
Consider this example:
echo "1\n2\n3\n3\n3\n4\n4" | awk 'BEGIN {getline;X=$0;print $0};
{if ($0 !~ X) {print $0;X=$0}}'
Instead of printing seven lines 1,2,3,3,3,4,4
this would merely print four, unique lines: 1,2,3,4.
As noted in the preceeding posts, the '-u' option of sort or the 'uniq' filter are general methods for accomplishing this.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2001 04:00 PM
01-08-2001 04:00 PM
Re: Korn shell programming
To reduce the number of iterations within the for loop for performance reasons, add an additional "| uniq" behind "awk '{print $1}'" in Ovidiu's script.
Hope this helps. Regards.
Steven Sim
Brainbench MVP for Unix Admin
http://www.brainbench.com