Reading first column of file which start with space also


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading first column of file which start with space also
# 1  
Old 07-29-2013
Reading first column of file which start with space also

Hi All,

I am trying to read first column of my file using command
Code:
cat temp2_sample.cir|cut -d' ' -f1

The content of my file is as follow
Code:
          R1    pin23I    pin27I
R2    pin23G    pin27G
R3    pin27F    pin27D
    RWire10    pin15Y    pin23J
VCC1    pin27W    pin13Y
                                      RWire21    pin28W    pin27B

Here I am getting output as
Code:
R1
R2
R3
RWire10
VCC1

I am not getting RWire21 in my output. Initially I thought it could be due to more space but if that is the case then R1 and RWire10 should also be not printed.
Please advise me where I can do changes in my command.
Thanks and Regards

---------- Post updated at 03:46 AM ---------- Previous update was at 03:44 AM ----------

Please consider space before R1 and both RWire. It is not showing in forum.

Moderator's Comments:
Mod Comment Use code tags please, see PM.

Last edited by zaxxon; 07-29-2013 at 06:04 AM.. Reason: code tags
# 2  
Old 07-29-2013
Quote:
Originally Posted by diehard
Hi All,

I am trying to read first column of my file using command
Code:
cat temp2_sample.cir|cut -d' ' -f1

The content of my file is as follow

R1 pin23I pin27I
R2 pin23G pin27G
R3 pin27F pin27D
RWire10 pin15Y pin23J
VCC1 pin27W pin13Y
RWire21 pin28W pin27B

Here I am getting output as
R1
R2
R3
RWire10
VCC1
I am not getting RWire21 in my output. Initially I thought it could be due to more space but if that is the case then R1 and RWire10 should also be not printed.
Please advise me where I can do changes in my command.
Thanks and Regards

---------- Post updated at 03:46 AM ---------- Previous update was at 03:44 AM ----------

Please consider space before R1 and both RWire. It is not showing in forum.
Please use code tags for code and data sample.

try

Code:
awk '{ print $1}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 07-29-2013
Code:
sed 's/^ //g' temp2_sample.cir | awk -F" "  '{print $1}'

# 4  
Old 07-29-2013
No change I am getting same result.
Here is my file
Code:
          R1    pin23I    pin27I
R2    pin23G    pin27G
R3    pin27F    pin27D
    RWire10    pin15Y    pin23J
VCC1    pin27W    pin13Y
                                      RWire21    pin28W    pin27B

# 5  
Old 07-29-2013
Getting same result using which code?
If you use Pamu's code you should get something like:
Code:
$ cat infile
          R1    pin23I    pin27I
R2    pin23G    pin27G
R3    pin27F    pin27D
    RWire10    pin15Y    pin23J
VCC1    pin27W    pin13Y
                                      RWire21    pin28W    pin27B
$ awk '{print $1}' infile
R1
R2
R3
RWire10
VCC1
RWire21

This User Gave Thanks to zaxxon For This Post:
# 6  
Old 07-29-2013
Thanks All for your reply.
I am getting result with pamu's code.
But I still dont understand why there is issue with cat and cut command.
# 7  
Old 07-29-2013
cut will treat every space delimiter as separate column. so eliminating the spaces and aligning the output will be good with cut. awk will be able to handle task like this easily.
This User Gave Thanks to ryandegreat25 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading the value of particular column from csv file

Hi Folks, I have the below csv file which is comma delimited , now from this file i need to read the value of the column der_id and then want to create a separate text file which will contain the value of the column der_id only please advise how to read the value of the column der_id and then... (3 Replies)
Discussion started by: punpun66
3 Replies

2. Shell Programming and Scripting

Reading line by line from live log file using while loop and considering only those lines start from

Hi, I want to read a live log file line by line and considering those line which start from time stamp; Below code I am using, which read line but throws an exception when comparing line that does not contain error code tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies

3. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

4. UNIX for Dummies Questions & Answers

Extracting rows from a space delimited text file based on the values of a column

I have a space delimited text file. I want to extract rows where the third column has 0 as a value and write those rows into a new space delimited text file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

5. UNIX for Dummies Questions & Answers

Adding tags to a specific column of a space delimited text file

I have a space delimited text file with two columns. I would like to add NA to the first column of the text file. Input: 19625 10.4791768259 19700 10.8146489183 19701 10.9084026759 19702 10.9861346978 19703 10.9304364984 Output: NA19625 10.4791768259 NA19700 10.8146489183... (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

How to start reading from the nth line till the last line of a file.

Hi, For my reuirement, I have to read a file from the 2nd line till the last line<EOF>. Say, I have a file as test.txt, which as a header record in the first line followed by records in rest of the lines. for i in `cat test.txt` { echo $i } While doing the above loop, I have read... (5 Replies)
Discussion started by: machomaddy
5 Replies

7. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

8. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

9. Shell Programming and Scripting

Reading a column from xls file using perl

Hi Everyone! I have a problem in reading a specific column from .xls file using perl language and then manipulating on given criteria. Detailed Description of the problem:: I have one .xls file, in which i have to populate two columns based on Period_date column which is in same file. My... (1 Reply)
Discussion started by: kvth
1 Replies

10. Shell Programming and Scripting

PERL: reading 2 column data into Hash file

I am trying to read in a 2 column data file into Perl Hash array index. Here is my code. #!/usr/bin/perl -w use strict; use warnings; my $file = "file_a"; my @line = (); my $index = 0; my %ind_file = (); open(FILE, $file) or die($!); while(<FILE>) { chomp($_); if ($_ eq '') { ... (1 Reply)
Discussion started by: subhap
1 Replies
Login or Register to Ask a Question