Changing the appearance of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing the appearance of a file
# 1  
Old 07-21-2014
Changing the appearance of a file

Hello,

I have a file. The content of the file is shown below.

Code:
>AB34.txt
65
66
67
68
>2D2Z.txt
61
62
>2D2Z.txt
92
93
94
>3E50.txt
106
107
>3E50.txt
153
154
>3E50.txt
158
159
160
>567A.txt
54
55

In the above example, 2D2Z.txt has two groups. I would like to print it as 2D2Z_1.txt and
2D2Z_2.txt. My desired output is shown below.

Code:
>AB34.txt
65
66
67
68
>2D2Z_1.txt
61
62
>2D2Z_2.txt
92
93
94
>3E50_1.txt
106
107
>3E50_2.txt
153
154
>3E50_3.txt
158
159
160
>567A.txt
54
55

Your help would be appreciated!!
# 2  
Old 07-21-2014
remember to give the filename twice as given in the below code
Code:
awk 'NR == FNR {if(/>.*\.txt/) {if($0 in a) b[$0]; a[$0]}; next}
  {if($0 in b) {split($0, f, "."); $0 = (f[1] "_" ++b[$0] "." f[2])}}1' file file

This User Gave Thanks to SriniShoo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting Word Appearance

How do you write a script that counts the number of times a word appears in a file and output it? Original: ID1 SMARCB1;Adil;Jon ID2 Jon;Annie;Mei ID3 Adil;Spaghetti;NBA ID4 Raptors;wethenorth;SMARCB1 ID5 SMARCB1;wethenorth Objective: SMARCB1: 3 Adil: 2 Jon: 2... (5 Replies)
Discussion started by: Lipidil
5 Replies

2. Shell Programming and Scripting

changing a file when the inode modified time of the other file changes

i have a requirement where i needed to change variable values in a properties file(first file) whenever there is change to Release details file(second file). My question is do i have to create a daemon process that always checks the modified time/inode change of the second file and then change the... (1 Reply)
Discussion started by: saikiran_1984
1 Replies

3. Shell Programming and Scripting

sed to find first appearance and append string

I have a file like below #GROUP A belongs to Asia GROUP A jojh hans local admin GROUP A gege fans michel jing jong #GROUP U belongs to USA GROUP U jeff goal hello world My requirement is to grep for first apperence of GROUP A which is not commented and append my name to end of file.... (12 Replies)
Discussion started by: vkk
12 Replies

4. UNIX for Dummies Questions & Answers

Changing file content based on file header

Hi, I have several text files each containing some data as shown below: File1.txt >DataHeader Data... Data... File2.txt >DataHeader Data... Data... etc. What I want is to change the 'DataHeader' based on the file name. So the output should look like: File1.txt >File1 ... (1 Reply)
Discussion started by: Fahmida
1 Replies

5. UNIX for Advanced & Expert Users

bash/grep/awk/sed: How to extract every appearance of text between two specific strings

I have a text wich looks like this: clid=2 cid=6 client_database_id=35 client_nickname=Peter client_type=0|clid=3 cid=22 client_database_id=57 client_nickname=Paul client_type=0|clid=5 cid=22 client_database_id=7 client_nickname=Mary client_type=0|clid=6 cid=22 client_database_id=6... (3 Replies)
Discussion started by: Pioneer1976
3 Replies

6. Shell Programming and Scripting

Show lines between frist and last appearance

Dear all, I want to show all lines between the first and the last appearance of a string in a file. This string is a input parameter of a script. I have some ideas with grep -n but i'm sure that I can get a better solution with SED or AWK thanks! (3 Replies)
Discussion started by: antuan
3 Replies

7. Shell Programming and Scripting

regular expression to match repeated appearance

Hi all, I am looking for a regex syntax to match repeated appearance. Likes, ']+]+' matches for string '65A SOME MORE AND 78B' Now, this gets messy if I need to extract all such repeated appearance. I don't want to write ] four or five times for matching repeated appearance. Thanks in... (2 Replies)
Discussion started by: guruparan18
2 Replies

8. Shell Programming and Scripting

how to find the line number of a pattern of first appearance??

Hi, I am doin a project in shell script please answer the above question..... waiting........ (2 Replies)
Discussion started by: shivarajM
2 Replies

9. UNIX for Advanced & Expert Users

Changing the appearance of an Output in console

I want to change the appearance of a message I got in UNIX console. Eg: In console: "no server running" I need it as "****no server running*****". Thanks in advance. (3 Replies)
Discussion started by: thomaa80
3 Replies
Login or Register to Ask a Question