Put Header on Text file of all column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put Header on Text file of all column
# 1  
Old 02-27-2012
Bug Put Header on Text file of all column

Hi

I have in put file A.txt

Code:
ABCDE1 JFHFJFJF3 1 1 SC1 12/10
ABCDE2 JFHFJFJF5 1 1 SC1 12/10
ABCDE3 JFHFJFJF5 1 1 SC1 12/10
ABCDE4 JFHFJFJF6 1 1 SC1 12/10

I want output in .csv with header:

Code:
Name     SUb_N     x y  No  Board
ABCDE1 JFHFJFJF3 1 1 SC1 12/10
ABCDE2 JFHFJFJF5 1 1 SC1 12/10
ABCDE3 JFHFJFJF5 1 1 SC1 12/10
ABCDE4 JFHFJFJF6 1 1 SC1 12/10

Five Column And five Header name:


Thanks

Last edited by pareshkp; 02-27-2012 at 05:50 AM..
# 2  
Old 02-27-2012
This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 02-27-2012
Code:
$ echo "Name     SUb_N     x y  No  Board" ; cat infile
Name     SUb_N     x y  No  Board
ABCDE1 JFHFJFJF3 1 1 SC1 12/10
ABCDE2 JFHFJFJF5 1 1 SC1 12/10
ABCDE3 JFHFJFJF5 1 1 SC1 12/10
ABCDE4 JFHFJFJF6 1 1 SC1 12/10
$

# 4  
Old 02-27-2012
if you want in comma seperated values in file, then

Code:
 
echo "Name,SUb_N,x,y,No,Board" > a.csv 
sed 's/ /,/g' input.txt >> a.csv

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 02-27-2012
Code:
sed -i '1i Name     SUb_N     x y  No  Board' inputfile

# 6  
Old 02-27-2012
Hi.

Placing a header onto a data file can be done in a number of ways as shown in previous posts. Here is how it might look if 2 files are combined and the columns are then aligned:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate addition of header and column alignment, align.
# align perl script: http://freecode.com/projects/align

pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C align

FILE1=${1-data1}
shift
FILE2=${1-data2}

pl " Data files:"
pe
pe "$FILE1:"
cat $FILE1
pe
pe "$FILE2:"
cat $FILE2

pl " Results:"
cat $FILE1 $FILE2 |
align

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
align 1.7.0

-----
 Data files:

data1:
Name     SUb_N     x y  No  Board

data2:
ABCDE1 JFHFJFJF3 1 1 SC1 12/10
ABCDE2 JFHFJFJF5 1 1 SC1 12/10
ABCDE3 JFHFJFJF5 1 1 SC1 12/10
ABCDE4 JFHFJFJF6 1 1 SC1 12/10

-----
 Results:
Name   SUb_N     x y No  Board
ABCDE1 JFHFJFJF3 1 1 SC1 12/10
ABCDE2 JFHFJFJF5 1 1 SC1 12/10
ABCDE3 JFHFJFJF5 1 1 SC1 12/10
ABCDE4 JFHFJFJF6 1 1 SC1 12/10

See the comment in the script for the source of the perl script align.

Best wishes ... cheers, drl

( Edit 1, minor typo in text )

Last edited by drl; 02-27-2012 at 10:37 AM..
# 7  
Old 02-27-2012
missing coma delimeter in columns

hi

if coma delimeter missing in columns treat them as bad file and if it is not then gudfiles. just checking columns not data.

id,name,sal,deptno
1,awa,200,10
2,aba,100,20
3,cdc,300,30 this is gudfile


idname,sal,deptno
1,awa,200,10
2,aba,100,20
3,cdc,300,30 this is badfile since its missing the coma(,)

thanks.
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

Split file by column value, each with header

Hello all, I have a csv with with different testcase values in column 5. year,min,max,Instrument,Testcase 2016,201,1003,GEOTROPH-02116,TATA7980 2016,53,1011,GEOTROPH-01963,TATA7980 2016,3,1024,GEOTROPH-02067,TATA7980 2016,203,1027,GEOTROPH-02011,TATA7980... (16 Replies)
Discussion started by: senhia83
16 Replies

3. UNIX for Dummies Questions & Answers

Column Header in the Spool file

Hi All, I have a problem with the column heading while spooling the data from the database. Since i want the column header, therefore i am not using SET HEADING OFF, and i am getting the header, but for the longer column name, some of the character from the column name is missing. for... (7 Replies)
Discussion started by: Pramod_009
7 Replies

4. UNIX for Dummies Questions & Answers

Rename a header column by adding another column entry to the header column name

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (1 Reply)
Discussion started by: Vavad
1 Replies

5. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

6. Shell Programming and Scripting

Get a column from one file and put it in another

I have 2 files that I would need from one file the 3rd column and put into the second file. Preferably in KSH . For example file one has file1: Column 1 Column 2 Column 3 Column 4 Column 5 file2: Column 1 Column 2 Column 3 Column 4 Column 5 So take Column 3 and put into file1 making it... (4 Replies)
Discussion started by: bombcan1
4 Replies

7. Shell Programming and Scripting

how can I bcp out a table into a text file including the header row in the text file

Hi All, I need to BCP out a table into a text file along with the table headers. Normal BCP out command only bulk copies the data, and not the headers. I am using the following command: bcp database1..table1 out file1.dat -c -t\| -b1000 -A8192 -Uuser -Ppassword -efile.dat.err Regards,... (0 Replies)
Discussion started by: shilpa_acc
0 Replies

8. Shell Programming and Scripting

Put header if file exists in a directory

Hi all, I will have to check a directory which is full of files. If any file more than 5 MB of space exists, write on it's head "Checked". Please help me. Thanks in advance! Deepak (5 Replies)
Discussion started by: naw_deepak
5 Replies

9. Shell Programming and Scripting

Grep strings from file and put in Column

Dear Experts, My file contains below- GET:SUB:ISI,432350414557432; RESP:0:MD,019352020633:ISI,432350414557432:T11,1:T21,1:T22,1:B16,1:T62,1:BAIC,0:BAOC,1:BOIC,0:BIRO,0:BORO,0:PAID,1; GET:SUB:ISI,432350414581060;... (2 Replies)
Discussion started by: thepurple
2 Replies

10. Shell Programming and Scripting

Convert Header into Column in Text file

Hi Gurus, I have a requirement like this and have to create a UX shell scripts. Thanks in advance. File-in: ------ Header2007-12-012007-11-21 100|xyz|was 101|wsa|qws ...... ....... Output should be: ------------------- 2007-12-01|100|xyz|was 2007-12-01|101|wsa|qws ...... .......... (7 Replies)
Discussion started by: vsubbu1000
7 Replies
Login or Register to Ask a Question