11-30-2009
there's a number of different ways you can do this, one example is cut/paste
cut f1 file > tmp1; cut f2 file > tmp2; cut f3 file > tmp3; etc etc
paste tmp1 tmp2 tmp3 tmp4 > file
rm -f tmp*
something like that, 'man cut' for more info.
also grep, awk, some cool loops, input field seperator... etc
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Folks, I am wondering if anyone solve this problem.
What I want to know is,
1. Delete all white spaces including leading blank space in each line (e.g. line 2), and replace such spaces by single tab except leading blank space
2. Then, align all columns to the right. But, output white space... (1 Reply)
Discussion started by: Jae
1 Replies
2. Shell Programming and Scripting
Hi,
I have this problem that there are blank spaces in my text file... i want to remove them
line 1
line 2
line 3
I want to remove the space between line 2 and line 3... I tried sed... it work but it prints the whole text file at the command prompt which i dont want....
sde i tried was... (4 Replies)
Discussion started by: bhagya2340
4 Replies
3. Shell Programming and Scripting
Hello All,
I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out.
My file is like this (<b> means one blank space, <t> means one tab space)-
$ cat file
NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies
4. Shell Programming and Scripting
I have a file which has blank spaces($) and the blank spaces at the end of the file are not coming up while cutting the files.. please find the following file, desired output..
file1:
001_AHaris$$$$$020$$$$$$$$$
001_ATony$$$$$$030$$$$$$$$$
002_AChris$$$$$090$$$$$$$$$... (5 Replies)
Discussion started by: techmoris
5 Replies
5. UNIX for Dummies Questions & Answers
Hello,
I am an super newbie, so forgive my sheer ignorance. I have a series of text files formatted as follows (just showing the header and first few lines):
mean_geo mean_raw lat lon
0.000 0 -70.616 163.021
0.000 0 -70.620 163.073
0.000 ... (8 Replies)
Discussion started by: vtoniolo
8 Replies
6. Shell Programming and Scripting
hi
i have a file which store some data.the contents of my file is
data1:data2
data3:data4
i have a script which read this file
correct="$(cat /root/sh | cut -d: -f1)"
i used this syntax..please help me which syntax is used to remove blank spaces..then how to read this file.. (1 Reply)
Discussion started by: shubhig15
1 Replies
7. Shell Programming and Scripting
Hello..
I have a text file. I want to remove all the blank spaces(except tab) from the file..
I tried using sed command as shown below
sed 's/ //g' file1
But the problem with the above command is that it also eliminates 'tab' which is between the columns..
For example if the contents... (7 Replies)
Discussion started by: abk07
7 Replies
8. UNIX for Advanced & Expert Users
Hi Gurus,
Somebody can say me how to delete blank spaces and blank lines in a file unix, please.
Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies
9. Shell Programming and Scripting
Hello Team,
Could you please help me with the below question?
I have a file with the following properties
1) File Delimiter is ;
2) Text columns are within double quotes
3) Numeric columns will not have double quotes
4) File has total 6 columns
Please see a sample record from file
... (3 Replies)
Discussion started by: sam99
3 Replies
10. Shell Programming and Scripting
Hi Guru,
I need some advice on how to add blank spaces to the code, rather than me just adding <space-bar spaces> which does not work.
Current output of the code
File System Backed Up - ALL_LOCAL_DRIVES
Daily - Incremental Backup Schedule - 1 Month Retention
• 7pm - PRD... (2 Replies)
Discussion started by: Junes
2 Replies
cut(1) General Commands Manual cut(1)
Name
cut - cut out selected fields of each line of a file
Syntax
cut -clist [file1 file2...]
cut -flist [-dchar] [-s] [file1 file2...]
Description
Use the command to cut out columns from a table or fields from each line of a file. The fields as specified by list can be fixed length,
that is, character positions as on a punched card (-c option), or the length can vary from line to line and be marked with a field delim-
iter character like tab (-f option). The command can be used as a filter. If no files are given, the standard input is used.
Use to make horizontal ``cuts'' (by context) through a file, or to put files together in columns. To reorder columns in a table, use and
Options
list Specifies ranges that must be a comma-separated list of integer field numbers in increasing order. With optional - indicates
ranges as in the -o option of nroff/troff for page ranges; for example, 1,4,7; 1-3,8; -5,10 (short for 1-5,10); or 3- (short
for third through last field).
-clist Specifies character positions to be cut out. For example, -c1-72 would pass the first 72 characters of each line.
-flist Specifies the fields to be cut out. For example, -f1,7 copies the first and seventh field only. Lines with no field delim-
iters are passed through intact (useful for table subheadings), unless -s is specified.
-dchar Uses the specified character as the field delimiter. Default is tab. Space or other characters with special meaning to the
shell must be quoted. The -d option is used only in combination with the -f option, according to XPG3 and SVID2/SVID3.
-s Suppresses lines with no delimiter characters. Unless specified, lines with no delimiters are passed through untouched.
Either the -c or -f option must be specified.
Examples
Mapping of user IDs to names:
cut -d: -f1,5 /etc/passwd
To set name to the current login name for the csh shell:
set name=`who am i | cut -f1 -d" "`
To set name to the current login name for the sh, sh5, and ksh shells:
name=`who am i | cut -f1 -d" "`
Diagnostics
"line too long" A line can have no more than 511 characters or fields.
"bad list for c/f option"
Missing -c or -f option or incorrectly specified list. No error occurs if a line has fewer fields than the list calls
for.
"no fields" The list is empty.
See Also
grep(1), paste(1)
cut(1)