Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Cutting the first 8 chars of a 2nd column Post 302178973 by era on Wednesday 26th of March 2008 05:20:58 PM
Old 03-26-2008
Except many versions of sed don't understand \t, and that's a pretty wacky thing to do anyway. If you really have trouble coping with tabs then put it in a variable and use that.

Code:
tab='	'  # make sure you get it right this one time (^:
sed -e "/\\(${tab}........\\).*/\\1/"

That's the whole program.

If you want to play around with a while loop then why not let read take care of the splitting. With IFS= you can tell it that the fields are tab separated.

Code:
while IFS='	' read first second  # that's a tab there between the quotes again
do
    echo "$first" | tr '\012' '\011'  # convert first newline to tab
    echo "$second" | cut -c1-8
done <my_file

If you have trouble typing a literal tab at the command line, try ctrl-v tab.

Last edited by era; 03-29-2008 at 07:51 PM.. Reason: Correct octal code for tab, duh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help recurrently cutting single column file

Hi there ! I have file with single column. I want to cut that column at fixed number of rows each time and paste in another file, in a way that in new file, the each cutting appear as separate columns. I mean cutting file with one column of 10000 rows, with 100 rows each time, and in new file... (3 Replies)
Discussion started by: jacks
3 Replies

2. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

3. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

4. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

5. UNIX for Dummies Questions & Answers

[Q] cutting from one column and pasting to another

I have a file laid out in columns with the first two lines line being: 219 432 4567 219 432 4587 I need to create a single line command to cut the characters in the 5th column and paste them back to the first column in the same file. (Hint:Two good solutions exist, one in which you use a... (9 Replies)
Discussion started by: mcampos7
9 Replies

6. Shell Programming and Scripting

Calculate 2nd Column Based on 1st Column

Dear All, I have input file like this. input.txt CE2_12-15 3950.00 589221.0 9849709.0 768.0 CE2_12_2012 CE2_12-15 3949.00 589199.0 9849721.0 768.0 CE2_12_2012 CE2_12-15 3948.00 589178.0 9849734.0 768.0 CE2_12_2012 CE2_12-52 1157.00 ... (3 Replies)
Discussion started by: attila
3 Replies

7. Shell Programming and Scripting

Transpose from 2nd column till the last column

Hi I have 5 columns like this a b c d e f g h i j k l m n o From 2nd column till the 5th column of every record, I would like to transpose them as rows, so my output file contains only one row a b c d e f g h i j (9 Replies)
Discussion started by: jacobs.smith
9 Replies

8. UNIX for Dummies Questions & Answers

Cutting only the 1st column data

Hi All, I having a data file which consists of 20cr records in it. The 1st column is year field which consist of year in format 200809 and fields are seperated with ^. How do i trim it to 2008 in file and save it in a quick time as there are many records so that i can use the file for loading... (3 Replies)
Discussion started by: abhi_123
3 Replies

9. Shell Programming and Scripting

Cutting a column and pasting its number

Hello Gurus, This is my first ever post here. I tried looking for similar material but came up empty handed. Apologies if this is too verbose or if I'm not using the correct formatting. I have files containing a fixed number of elements per line; separator is a single space. Each line has the... (4 Replies)
Discussion started by: stdroid
4 Replies

10. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies
XmTabListRemoveTabs(library call)										 XmTabListRemoveTabs(library call)

NAME
XmTabListRemoveTabs -- A convenience function that removes noncontiguous tabs SYNOPSIS
#include <Xm/Xm.h> XmTabList XmTabListRemoveTabs( XmTabList oldlist, Cardinal *position_list, Cardinal position_count); DESCRIPTION
XmTabListRemoveTabs removes noncontiguous tabs from a tab list. The function creates a new tab list by copying the contents of oldlist and removing all tabs whose corresponding positions appear in the position_list array. A warning message is displayed if a specified position is invalid; for example, if the value is a number greater than the number of tabs in the tab list. tablist Specifies the tab list. The function deallocates oldlist and the tabs it contains after extracting the required information. position_list Specifies an array of the tab positions to be removed. The position of the first tab in the list is 0 (zero), the position of the second tab is 1, and so on. position_count Specifies the number of elements in the position_list. RETURN
If oldlist or position_list is NULL, or position_count is 0 (zero), returns oldlist. Otherwise, this function returns the new tab list. The function allocates space to hold the returned tab list. The application is responsible for managing the allocated space. The applica- tion can recover the allocated space by calling XmTabListFree. RELATED
XmTabList(3) and XmTabListFree(3). XmTabListRemoveTabs(library call)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy