Modifying the header in a flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modifying the header in a flat file
# 1  
Old 04-08-2013
Modifying the header in a flat file

Hi,

I need to modify the header of the flat file, can you provide me the code

example: Temp.txt
Code:
header: list_col1|list_col2|list_col3
data:    1|2|3

in the above header should be modified in the prescribed format(is available with me)

Code:
Header: List_Col1|List_Col2|List_Col3

A bit urgent, let me know

Last edited by radoulov; 04-08-2013 at 09:47 AM..
# 2  
Old 04-08-2013
Code:
awk '/^header/ {sub("header","Header"); gsub("list_col","List_Col")}1' file

# 3  
Old 04-08-2013
Here is another solution:
Code:
awk '
        NR == 1 {
                        $1 = toupper (substr($1, 1, 1)) substr($1, 2)

                        n = split($2, A, "|")
                        for (i = 1; i <= n; i++)
                        {
                                k = split(A[i], B, "_")
                                for (j = 1; j <= k; j++)
                                {
                                        B[j] = toupper (substr(B[j], 1, 1)) substr(B[j], 2)
                                        s = (s == "" ? B[j] : s "_" B[j])
                                }
                                c = (c == "" ? s : c "|" s)
                                s = ""
                        }
                        $2 = c
} 1 ' file

# 4  
Old 04-08-2013
@Yoda: Which one you think here is efficient? Smilie
# 5  
Old 04-08-2013
Quote:
Originally Posted by PikK45
@Yoda: Which one you think here is efficient? Smilie
It is indeed your solution. No doubt about it. It is simple and elegant. Smilie

But I just posted this code just in case if OP requires a generic solution.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

Modifying listener file

Hi Pros, I'm writing a script to modify listener.ora file on multiple hosts. When I ssh to any server from a central server in our environment we are presented with menu to select the instance. I need to set my environment to listener which could be different number on every instance. How can I... (5 Replies)
Discussion started by: humble_learner
5 Replies

3. Shell Programming and Scripting

Modifying file to 75 characters

I have a text file containing some notes and I want to limit the lines to 75 characters. Tried using fold, however fold will cut words. Need something in bash, sed or awk to do this. Find the blank space less than 75 ant cut from there (10 Replies)
Discussion started by: kristinu
10 Replies

4. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

5. Shell Programming and Scripting

Comparing one file header with another file header

Hi Experts, In our project we have requirement where in we have to compare header of one file with header in the parameter file. There are 20 files which we ftp from one site. All this files have different header. We are comapring this file with our parameter file(which is having the header... (2 Replies)
Discussion started by: Amey Joshi
2 Replies

6. Shell Programming and Scripting

Modifying a file?

Hi, I want to convert a file that looks like this >joe XXXXXXXXXXXXXXXXXXX >man BBBBBBBBBBBBBBBBBBBBBSSSSSSSS to something that looks like this (where the spacing is tab seperated) joe XXXXXXXXXXXXXXXXXXX man BBBBBBBBBBBBBBBBBBBBBSSSSSSSS I am able to do the reverse but the other... (3 Replies)
Discussion started by: kylle345
3 Replies

7. Shell Programming and Scripting

modifying file using script

Hi, I am new to shell programming, and want to know is it possible to change the contents of file using script? for example, if want to search 2 words and want to replace these words with 2 new words. Regards, Manoj (4 Replies)
Discussion started by: manoj.solaris
4 Replies

8. Shell Programming and Scripting

Modifying file from outside

hi , I have a javascript file like this: function fnValidateId(){ var array_id = new Array("444","7888","6633","555","146562","3333","33332") var tmp_id = document.form1.id.value; var num=0; while(1) { if(tmp_id ==... (9 Replies)
Discussion started by: Sreejith_VK
9 Replies

9. Shell Programming and Scripting

can someone help me with modifying this file

Hi, I have a file which has data kind of like this. Apr 13 08:20:38 uslis10a sendmail: m3DDKSx3006432: usliss26.ca.com Apr 13 08:20:38 uslis10b sendmail: m3DDKSoK006433: usliss26.ca.com Apr 13 08:20:38 uslis10b sendmail: m3DDKcSo006442: usliss26.ca.com Apr 13 08:20:38 uslis10c... (2 Replies)
Discussion started by: eamani_sun
2 Replies

10. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies
Login or Register to Ask a Question