- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Small help in shell script
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
06-12-2004 04:40 AM
06-12-2004 04:40 AM
I have 2 files..lets take A and B
I want a shell script such that, it must read first line from file "A" and 2 line from "B". This must repeat for whole file a.
I think you are confused..Let me explain with an example...
"A" file containes
1
2
3
and "B" file containes
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
now i want output like
1 aaa
1 bbb
2 ccc
2 ddd
3 eee
3 fff
4 ggg
4 hhh
This is very importaant and urgent...Please friends help me fast...
Thnks in advance
***** Problem is a problem untill U feel that is a Problem****
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 05:09 AM
06-12-2004 05:09 AM
Re: Small help in shell script
# perl -le'$b=pop;@a=<>;@ARGV=($b);@b=<>;for(@a){print$_,splice@,0,3}' fileA fileB
will do it. No error checks on fileb having at least 3 times the lines fileA has
There are several variants to this of course. Above looked the shortest
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 05:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 05:23 AM
06-12-2004 05:23 AM
Re: Small help in shell script
# awk '{printf "%s\n%s\n", $0, $0}' A > AA
# paste AA B
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 05:36 AM
06-12-2004 05:36 AM
Re: Small help in shell script
# perl -e'$b=pop;chomp(@a=<>);@ARGV=($b);@b=<>;for$a(@a){print"$a $_"for splice@b,0,3}' fileA fileB
Lets test ...
lt09:/home/merijn 126 > perl -e'$b=pop;chomp(@a=<>);@ARGV=($b);@b=<>;for$a(@a){print"$a $_"for splice@b,0,3}' fileA fileB
1 aaa
1 bbb
1 ccc
2 ddd
2 eee
2 fff
3 ggg
3 hhh
lt09:/home/merijn 127 >
Sorry if that caused confusion
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 05:36 AM
06-12-2004 05:36 AM
Re: Small help in shell script
I get the following eror for:
# perl -le '$b=pop;@a=<>;@ARGV=($b);@b=<>;for(@a){print $_,splice @,0,3}' A B
Number found where operator expected at -e line 1, near "@,0"
(Missing operator before 0?)
syntax error at -e line 1, near "@,0"
Execution of -e aborted due to compilation errors.
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 05:44 AM
06-12-2004 05:44 AM
Re: Small help in shell script
Enjoy, Have FUN!H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 10:08 AM
06-12-2004 10:08 AM
Re: Small help in shell script
# perl -e'$b=pop;chomp(@a=<>);@ARGV=($b);@b=<>;for$a(@a){print"$a $_"for splice@b,
0,2}' A B
did the trick for me.. excellent much neater than my "awk & paste"
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 07:28 PM
06-12-2004 07:28 PM
Re: Small help in shell script
It helped me a lot.. Thnks ....
Thnks for others also..But I don't know perl. But after seeing your answers..I feel perl is better and faster.
***** Problem is a problem untill U feel that is a Problem****
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2004 08:38 PM
06-12-2004 08:38 PM
Re: Small help in shell script
The more you are familiar with /any/ language, the more you will use it, and the faster it will bring you to the desired results.
I know people that wrote 2000 line sys-admin scripts in csh. I bet that there are more people on this forum that shivver to maintain that than there are people that shivver to decrypt one of my perl one-liners :)
I know perl, because I use it for almost everything, but until you are familiar with it, awk, sed, sh, sort, and comm are proably better utilt for you than Perl. Even if the given solution is faster and/or `better'.
I was tired yesterday, obviously. the typo (missing 'b') in my first post is due to my keyboard, that often needs a harder hit for the 'b' key, but the misreading of your post, and the second misreading of 3 instead of two is simply sloppy and careless.
Perl is a fine language for scripting, because it is so versatile, and has all the needed glue elements built-in. I can understand people not using it for bigger projects due to the sometimes obfuscated constructs, but IMHO there also lies the grace of it. Perl is much more powerful and versatile than Python for example, but in larger development groups, I can imagine that the group benefits from the restrictive formats and structures of Python.
I, for example, never use posix-sh features, but restrict myself, when programming sh, to the very old bourne shell set just because of (backward) compatibility.
Enjoy (scripting), Have FUN! H.Merijn [ always there to promote Perl ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2004 11:37 PM
06-13-2004 11:37 PM
Re: Small help in shell script
Attached script will do the requirement. But b file has to contain twice the lines as in a file. If you don't want to check this remove the checking loop in script.
Give the input files and result file,you will get the required results on result file.
Regards,
Muthukumar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2004 12:26 AM
06-14-2004 12:26 AM
Re: Small help in shell script
U wrote a really big program..Sorry yaar..I did'nt like it..Shell scrip must me sweet and short..
Any way thnks for your replay...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2004 12:51 AM
06-14-2004 12:51 AM
Re: Small help in shell script
Enjoy, Have FUN! H.Merijn