The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with output of find command being input to basename command... new_learner UNIX for Dummies Questions & Answers 2 12-14-2008 02:56 AM
awk/sed Command : Parse parameter file / send the lines to the ksh export command rajan_san Shell Programming and Scripting 4 11-06-2008 01:29 PM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 06:54 AM
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 08:12 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl SuSE 5 07-30-2007 08:26 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-21-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Cat command help

I want to concatenate 100 files to one file and append file name in each record to find out which file it came from

Code:
for a in $(<shal_group)
do
cat $a >> bigoutput.group
The above code put all files in one file but i want file name appended to each file

Record should be like this
file1| data ...
fiel2| data....

Appreciate your help
  #2 (permalink)  
Old 04-21-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:
for i in $(< shal_group)
do
    awk '{print FILENAME, "|", $0   }' $i
done > outputfile
  #3 (permalink)  
Old 04-21-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Quote:
Originally Posted by jim mcnamara View Post
Code:
for i in $(< shal_group)
do
    awk '{print FILENAME, "|", $0   }' $i
done > outputfile
Thanks jim mcnamara it works.
I need a minor change in this.

Record looks like this
/user/tmp/server1_etc_group| data ...
/user/tmp/server2_etc_group| data....

I want data like this
server1|data....
server2|data

Thank you sir
  #4 (permalink)  
Old 04-23-2009
abinaya abinaya is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 24
Hi,

Try the below code:

Code:
 
#!/bin/sh
for i in `cat concatinfile`
do
while read line
do
echo "`echo $i | cut -d"/" -f4 | cut -d"_" -f1`: $line" >> concatoutfile
done < $i
done

here "concatinfile" is the inputfile which contains the list of files to be concated.
"concatoutfile" is the output file

Reg,
Abinaya
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0