Filename pattern match and appending pipe


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filename pattern match and appending pipe
# 1  
Old 01-20-2010
Filename pattern match and appending pipe

Hi,

I have a directory with around 100k files and files with varying sizes(10GB files to as low as 5KB). All the files are having pipe dilimited records.

I need to append 7 pipes to the end of each record, in each file whose name contains _X3_ and need to append 10 pipes to the end of each record, in each file whose name contains _X7_.

I tried as below but it doesnt work, it changes for all files

Code:
for file in *
do
  {
    awk '{printf "%s,\"%s\"\n",$0,"|||||||"}' "$file"
    } > output && mv output "$file"
done

Thank You in advance
.

---------- Post updated at 12:57 PM ---------- Previous update was at 12:40 PM ----------

Thank you Franklin. Will use the Code tag in future.

Last edited by Franklin52; 01-20-2010 at 03:17 AM.. Reason: Please use code tags!
# 2  
Old 01-20-2010
try this.
Code:
 
for file in `ls *_X3_*`
do
    awk '{print $0"|||||||"}' $file> output 
    mv output $file
done

Or
if sed supports -i option
Code:
for file in `ls *_X3_*`
do
sed -i 's/$/|||||||/g' done
done


Last edited by xoops; 01-20-2010 at 03:41 AM..
# 3  
Old 01-20-2010
Quote:
Originally Posted by xoops
try this.
Code:
 
for file in `ls *_X3_*`

Useless use of ls, this is sufficient:
Code:
for file in *_X3_*

# 4  
Old 01-20-2010
Thank you , I did the following:
Code:
for file in *_X7_*
do
    awk '{print $0"|||||||"}' $file> output 
mv output $file
done


for file in *_X3_*
do
    awk '{print $0"|||||||"}' $file> output 
mv output $file
done

any better way?

Also I have multiple level of directories with each directory. I need to do the change in each and every directory where i can find a file with the filename having _X7_ or _X3_

Thank you in advance
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match filename pattern with -f

Hello All, I have two issues. 1).I want to check if directory exists and inside that if file exists with today's date minus one. I can check directory exists but how can i check only a pattern of filename in that directory.Name of file is files-20170105-09.gz. 2).Also i want to exit immediately... (6 Replies)
Discussion started by: looney
6 Replies

2. UNIX for Dummies Questions & Answers

Appending | (pipe) to end of each line which does not have it

I have a text file in which all records end with pipe character and newline, but a few do not have a pipe at the end. Something like this 1|John|32|US| 2|Matt|35|UK 3|Rex|36|EU| So in the above example the second line does not have a pipe at the end My requirement is to append a... (5 Replies)
Discussion started by: abhilashnair
5 Replies

3. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Appending beginning of filename to end

Hi Guys, I have serveral directories like this: (2013) blablabla(blabla) - blabla (blabla) or (1997) blablabla(blabla) - blabla (blabla) and have to rename them to something like that: blablabla(blabla) - blabla (blabla) (2013) and blablabla(blabla) - blabla (blabla) (1997) Easy... (2 Replies)
Discussion started by: Nateshift
2 Replies

5. Shell Programming and Scripting

Getting filename for Nth line pattern match

Hi, I have many scripts in particular directory. And few of the scripts have exit 0 in second line. Now i wanted to list out the scripts name which has the exit 0 in its second line I tried many options , but i can not get the filename along with the nth line pattern match :mad:. Can anyone... (14 Replies)
Discussion started by: puni
14 Replies

6. Shell Programming and Scripting

Appending string to match pattern (data processing)

Hello i have go the following result from performing 2 testing using the same file. I have used unix script to extract the result because the files are many as shown below. 01_gravity.f.tcov 7 3 42.86 02_gravity.f.tcov 9 4 80.86... (4 Replies)
Discussion started by: ganiel24
4 Replies

7. Shell Programming and Scripting

Concatenating and appending string based on specific pattern match

Input #GEO-1-type-1-fwd-Initial 890 1519 OPKHIJEFVTEFVHIJEFVOPKHIJTOPKEFVHIJTEFVOPKOPKHIJHIJHIJTTOPKHIJHIJEFVEFVOPKHIJOPKHIJOPKEFVEFVOPKHIJHIJEFVHIJHIJEFVTHIJOPKOPKTEFVEFVEFVOPKHIJOPKOPKHIJTTEFVEFVTEFV #GEO-1-type-2-fwd-Terminal 1572 2030... (7 Replies)
Discussion started by: patrick87
7 Replies

8. Shell Programming and Scripting

Does Filename Match Pattern

Hi, I am writing a BASH script. I have a list of files and I would like to make sure that each is of a specific pattern (ie *.L2). If not I would like to remove that file. How do I test whether a filename matches a given pattern? Thanks a lot. Mike (10 Replies)
Discussion started by: msb65
10 Replies

9. Shell Programming and Scripting

Appending date to filename

hi i need to rename a.txt to a_12052008.txt using the batch file i used reanme a.txt a_%date%.txt ......but its done nothing am using win2000 professional edition. system date format is : The current date is: Mon 2008-05-12 can anyone help me to rename thanks aemu (5 Replies)
Discussion started by: aemunathan
5 Replies

10. Shell Programming and Scripting

To identify filename in which having match PATTERN

Hi, Any idea to identify bunch of files( gz format) in which having match PATTERN wanted and print out those files ? :) Regards, (14 Replies)
Discussion started by: cedrichiu
14 Replies
Login or Register to Ask a Question