removing spaces from first column
Solution 1
If this is just an alignment issue, and you want to line up the data into columns:
$ column -t somefile
16504 16516
1650811 16520
1651 16524
16516111 16528
165204 16532
The -t
switch to column
will create a table from the source data, automatically:
-t, --table
Determine the number of columns the input contains and create a
table. Columns are delimited with whitespace, by default,
or with the characters supplied using the separator. Table output
is useful for pretty-printing.
Solution 2
You are likely after something like:
sed "s/^ *//" < your_file
which removes any leading spaces (replaces them with an empty string). If you also have variable number of spaces between the columns, you can extend it to:
sed "s/^ *//;s/ */ /g" < your_file
which (after removing the leading spaces) replaces any occurrence of one or more spaces with a fixed string (in this case 4 spaces). You may also want to use \s
instead of plain space in the matching pattern to cover cases where a Tab character is used.
Solution 3
You can try this:
awk '$1=$1' file
to remove all leading space in first column.
Related videos on Youtube
user61398
Updated on September 18, 2022Comments
-
user61398 over 1 year
My input file has positions in first column with different number of spaces (or no space)
16504 16516 1650811 16520 1651 16524 16516111 16528 165204 16532
I need to get an output file where fist column has no spaces at all, while keeping second column as it is.
16504 16516 16508 16520 16512 16524 16516 16528 16520 16532
-
S edwards about 10 yearsit's really unclear what you want,your example is a bit confusing, what do you want to do with data in first column ?
-
mulaz about 10 years^his comment + where did you get the "2" in 3rd line?
-
user61398 about 10 yearsDear Kiwy, Sorry my out put file shoul be same as input but removing all spaces.
-
Graeme about 10 yearsYour example doesn't have different numbers of spaces, it has different lengths of numbers!
-
user61398 about 10 yearsi wrote my input with different space, but i dont why it is not showing.
-
user61398 about 10 years16504 16516 1650811 16520 1651 16524 16516111 16528
-
Graeme about 10 yearsThe spaces show up now, I edited the question. You still need to explain the different length of numbers though.
-
S edwards about 10 yearsthe problem here is for this line for example:
16516111 16528
how it can become16516 16528
where are the trainling111
of your first column -
user61398 about 10 yearsThe numbers will be kept the same but i had problem while pasting the numbers in your editor. The ouput should be in this format : 16504 16516 1650811 16520 1651 16524 16516111 16528 165204 16532
-
Rahul Patil about 10 yearsif you want both column properly then you can use
column -t < input_file
-
slm about 10 yearsCan you please edit your input data or output data so that it includes the correct data? See the "edit" link above Graeme's name, click it to edit your question to refine it.
-
terdon about 10 yearsAlso, please read formatting help as peterph suggested.
-
-
S edwards about 10 yearsdidn't know this tool, it's really nice
-
slm about 10 years@Kiwy - yes that and
expand
is another useful tool. I useexpand
when I post examples of output that include tabs. It removes them, substituting in spaces in their place. You can control the number of spaces w/ it.