How to remove everything before 1st space in UNIX?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to remove everything before 1st space in UNIX?
# 1  
Old 06-12-2015
How to remove everything before 1st space in UNIX?

i need to remove all before 1st space

input :
Code:
206292
24436
1115   504
1115   1120793
1115   17453606
62931
547915
   108924
   305715
   23541
   19255
   315727
   1403954
   369685
2   1120793
1115      8
1115      165106
1115      1638
1115      474062
1115      21428
1115      806
1115      400
1115      1275
1115   4300
1115   28584


output i need

Code:
206292
24436
504
1120793
17453606
62931
547915
108924
305715
23541
19255
315727
1403954
369685
1120793
8
165106
1638
474062
21428
806
400
1275
4300
28584


Last edited by Corona688; 06-12-2015 at 01:01 PM..
# 2  
Old 06-12-2015
Code:
awk '{ print $NF }' inputfile > outputfile


Last edited by Don Cragun; 06-12-2015 at 04:17 PM.. Reason: Hide response to improperly filed homework request.
# 3  
Old 06-12-2015
I have quoted the relevant parts:

Quote:
Originally Posted by amyt1234
i need to remove all before 1st space

input :
Code:
1115   504
1115   1120793
1115   17453606

Code:
504
1120793
17453606

To me it seems you do not remove all before first space to arrive at this output from your input but in fact remove everything up to and including the last space, no? In fact, looking at what the proposed output from the input should be in other lines you want to get the last (rightmost) group of adjoining non-space characters in every line. Is that so?

Moderator's Comments:
Mod Comment Furthermore: we have special rules in place in this homework forum. If you posted here erronously contact a moderator to have this thread moved to the normal forum parts. If this is indeed homework you need to fill out the questionnaire, otherwise you will get no answers and the thread will be closed.


I hope this helps.

bakunin
# 4  
Old 06-16-2015
this is not my homework....its is just i need to learn few skills in unix.....i posted in in homework beacuse i dont get link to post in main forum......as i m new it will take some time for me to understand the functionality of this forum...so m sorry for trouble
# 5  
Old 06-16-2015
Moderator's Comments:
Mod Comment Since this isn't homework, I have moved this thread to the UNIX for Dummies Questions & Answers forum.

You can review the forum rules you agreed to when you joined the UNIX & Linux Forums here.

Does the suggestion Corona688 provided in post #2 in this thread work for you? If not, how is it failing to meet your needs?
# 6  
Old 06-17-2015
The O/P said "remove all before 1st space".
The following removes all up to and including the 1st space:
Code:
sed 's/^[^[:space:]]*[[:space:]]\{1,\}//' input

The difference is seen with lines like
Code:
aa  bb cc  dd
  xx yy zz

# 7  
Old 06-17-2015
The problem is that the English description of the desired output and the sample desired output shown in the 1st post in this thread do not match

The code suggested by Corona688 produces the sample output from the sample input (without caring about what appears before the first space.

The code MadeInGermany suggested removes any characters that appear before the 1st character in the space character class AND the 1st character in the space character class (which does not match the English description of the problem and does not produce the sample output).

The English description of the problem is incomplete. It doesn't say what should happen to an input line that does not contain a space. It could be interpreted to mean that if there is no space, no change is to be made (as is shown in the sample output for some sample input lines), or it could be interpreted to mean that all characters should be removed from lines that do not contain a space character. (And note that the description talks about "a space"; not a character in the space character class.)

The following script shows one way to meet the stated English requirements for either interpretation:
Code:
echo 'Remove before 1st space; do not change lines with no space:'
sed 's/^[^ ]* / /' input
echo
echo 'Remove before 1st space; change lines with no space to empty lines:'
sed 's/^[^ ]*//' input

and produces the output:
Code:
Remove before 1st space; do not change lines with no space:
206292
24436
   504
   1120793
   17453606
62931
547915
   108924
   305715
   23541
   19255
   315727
   1403954
   369685
   1120793
      8
      165106
      1638
      474062
      21428
      806
      400
      1275
   4300
   28584

Remove before 1st space; change lines with no space to empty lines:


   504
   1120793
   17453606


   108924
   305715
   23541
   19255
   315727
   1403954
   369685
   1120793
      8
      165106
      1638
      474062
      21428
      806
      400
      1275
   4300
   28584

which, of course, is nothing at all like the sample output provided!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove space with sed

Hello Folks , myfile contains 1000000 records as follows: logver=56 idseq=63256 itime=1111 devid=TG-40 devname=PUI-C2 vd=USER date=2019_01_10 time=18:39:49 logid="000013" type="traffic" subtype="forward" level="notice" eventtime=134 srcip=1.1.1.1 srcport=1 srcintf="XYX-CORE.01"... (3 Replies)
Discussion started by: arm
3 Replies

2. UNIX for Beginners Questions & Answers

How do I remove leading spaces in UNIX when count of space character is not fixed? Example below-

Script showStreamsGLIS$reg.$env.ksh gives me output as below- Job Stime Etime Status ExitCode GLIS-AS-S-EFL-LOCK-B ----- ----- OI 103313880/0 GLIS-ALL-Q-EOD-FX-UPDT-1730-B ----- ----- TE 0/0 GLIS-TK-S-BWSOD-B ... (8 Replies)
Discussion started by: Tanu
8 Replies

3. Shell Programming and Scripting

Remove Space and blank line from file in UNIX shell script

I have below file. I want to remove space at begining of every line and then after also remove blank line from file. I use below code for each operation. sed -e 's/^*//' < check.txt > check1.txt sed '/^\s*$/d' < check1.txt > check2.txt above code not remove all the space... (12 Replies)
Discussion started by: Mohin Jain
12 Replies

4. UNIX for Advanced & Expert Users

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print $2,$3,$7,$11,$15,$19,$23,$27,$31,$35($19/$15*100)}' 02:00:00... (1 Reply)
Discussion started by: bizomb
1 Replies

5. Shell Programming and Scripting

Remove trailing space

Hi I am trying to remove trailing space from a string. value=${value%% } It is not working. What might be the issue with the above snippet. (7 Replies)
Discussion started by: munna_dude
7 Replies

6. Shell Programming and Scripting

remove space

File A.txt A005 -119.5 -119.5 -100.5 A006 -120.5 -119.5 -119.3 A008 0 0 0 Output A005 -119.5 -119.5 -100.5 A006 -120.5 ... (1 Reply)
Discussion started by: asavaliya
1 Replies

7. Shell Programming and Scripting

remove space of each line

Hi Guys, I want remove starting space of each line ... My Input: A B C D E C V F G H F R T Y U D F G H J L O I U Y G P O K O P L O L O I P P O P P P P P My Output: A B C D E C V F G H (7 Replies)
Discussion started by: asavaliya
7 Replies

8. Shell Programming and Scripting

Remove space

DATE=6/Jul/2010 6/Jul/2010 var="sed -n '/\ ---------- Post updated at 11:49 AM ---------- Previous update was at 11:36 AM ---------- #!/bin/bash DATE=`./get_date.pl 3` DATE1=`./get_date.pl 2` var1=$( echo "$DATE" | sed "s/ //g" ) var2=$( echo "$DATE1" | sed "s/ //g" ) var="sed -n... (1 Reply)
Discussion started by: sandy1028
1 Replies

9. Shell Programming and Scripting

to remove space after numeric

I have a script that shows me the disk SPace used by different dir under my home dir: #!/bin/ksh cd /ednpdtu3/u01/pipe p1=`df -g | tail -1 | tr -s " " | cut -d " " -f2` echo "Total Disk Space of Home Dir is $p1 GB" p2=`df -g | tail -1 | tr -s " " | cut -d " " -f3` echo "Total Disk Space... (2 Replies)
Discussion started by: ali560045
2 Replies

10. Shell Programming and Scripting

remove space characters

hello I have this output ifspeed 100000000 ifspeed 100000000 collisions 413 collisions 10 duplex full duplex ... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies
Login or Register to Ask a Question