Insert a column in the beginning


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Insert a column in the beginning
# 1  
Old 11-20-2018
Insert a column in the beginning

Hi, I have been trying to see how i can insert a column in the beginning to my html table

This is how it looks

Code:
Name Age 
Sid     32   
John   33
Mary   34

I want to insert a column Job before Name column, so it looks like

Code:
Job      Name   Age 
IT        Sid       32   
Doctor John     33
Nurse   Mary    34

I tried with
HTML Code:
<thead><tr>Job</tr></thead>
<tr><td>IT</td></tr>
<tr><td>Doctor</td></tr>
<tr><td>Nurse</td></tr>
but the output looks
Code:
Job
IT
Doctor
Nurse
Name Age 
Sid     32   
John   33
Mary   34

# 2  
Old 11-20-2018
You will need to arrange it like <tr><td>column1</td><td>column2</td><td>column3</td></tr>

If you mean you want an automatic solution, what format do you have your input data in?
# 3  
Old 11-20-2018
Thanks for the reply, however this would insert one row and the different columns.

I have it as space delimited columns as the raw file
# 4  
Old 11-20-2018
Code:
<table>
  <tr>
    <th>Job</th>
    <th>Name</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>IT</td>
    <td>Sid</td>
    <td>32</td>
  </tr>
  <tr>
    <td>Doctor</td>
    <td>John</td>
    <td>33</td>
  </tr>
  <tr>
    <td>Nurse</td>
    <td>Mary</td>
    <td>34</td>
  </tr>
</table>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use sed to insert character in the beginning of file path?

I need to manipulate one Database file on Solaris 11 in which contains more than 5000 lines of data file path like this: '/data1/oradata/DBNAME/system01.dbf', '/data7/oradata/DBNAME/undotbs1_01.dbf', '/data1/oradata/DBNAME/sysaux01.dbf', '/data28/oradata/DBNAME/userdata01.dbf', ... (6 Replies)
Discussion started by: duke0001
6 Replies

2. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

3. Shell Programming and Scripting

Insert text at the beginning of every even number line

i am trying to insert text at the beginning of every even number line with awk i can do it with odd number lines with this command awk 'NR%2{$0="some text "$0}1' filehow can i edit this command thanks (5 Replies)
Discussion started by: bob123
5 Replies

4. Shell Programming and Scripting

Insert data in first column(if blank) from previous line first column

Dear Team I need to insert field(which is need to taken from previous line's first field) in first column if its blank. I had tried using sed but not find the way. Detail input and output file as below. Kindly help for same. INPUT: SCGR SC DEV DEV1 NUMDEV DCP ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

5. Shell Programming and Scripting

One of the awk column spilling on the new line from beginning

I am having a problem where the Compute field/column is spilling over to the new line. Here's the piece of code and the o/p:- Code Sniplet:- for id in `qstat -u "*" -q "$Queue" -s r |sed -n '3,$ p'|awk -F" " '{print $1}'` do NODELIST=`cat /scratch/$id.hostlist.*|awk -F" " '{print $1,$2}'|tr '... (5 Replies)
Discussion started by: grish
5 Replies

6. Shell Programming and Scripting

Insert output from a file to beginning of line with sed

Hi I've been trying to search but couldn't quite get the answer I was looking for. I have a a file that's like this Time, 9/1/12 0:00, 1033 0:10, 1044 ... 23:50, 1050 How do I make it so the file will be like this? 9/1/12, 0:00, 1033 9/1/12, 0:10, 1044 ... 9/1/12, 23:50, 1050 I... (4 Replies)
Discussion started by: diesel88
4 Replies

7. Shell Programming and Scripting

Insert at the beginning of odd lines

Hello people, I am trying with sed to insert some text at the beginning of each odd line of a file but no luck. Can you please help. Awk is also suitable but I am not very familiar with it. Thank you in advance for any help. (7 Replies)
Discussion started by: drbiloukos
7 Replies

8. Shell Programming and Scripting

SED - insert space at the beginning of line and multi replace command

hi I am trying to use SED to replace the line matching a pattern using the command sed 'pattern c\ new line ' <file1 >file 2 I got two questions 1. how do I insert a blank space at the beginning of new line? 2. how do I use this command to execute multiple command using the -e... (5 Replies)
Discussion started by: piynik
5 Replies

9. Shell Programming and Scripting

Need to insert text(constant) at the beginning of file

I am very new to scripting and I know this request is simple but I am having no luck with it. I have a file a.dat with the following data in it. aa bb cc dd I need to run a script that will take each line of a.dat and put dsjc/ubin/ in front of each record, so the output looks like ... (2 Replies)
Discussion started by: jclanc8
2 Replies

10. Shell Programming and Scripting

Insert two strings at the beginning and at the end of each line of a file

Hi, excuse me for my poor english. My problem is that: I have a File i want to add to each line of that file two strings: one at the beginning of the line, one at the ending. string1="abcd" string2="efgh" i want $string1 content $string2 for each line. Is that possible? (3 Replies)
Discussion started by: Linux-fueled
3 Replies
Login or Register to Ask a Question