Prev: vpath w/implicit pattern rule, & non-basename target (GNU make)
Next: grepping from last file of a listing......
From: Janis Papanagnou on 6 Jun 2010 10:16 shulamitm wrote: > On 6 יוני, 12:50, superpollo <ute...(a)esempio.net> wrote: >> shulamitm ha scritto: >> >> >> >> >> >>> Hello, >>> I'm looking for solution to the following problem: >>> I have a file contains 2 fileds, but in a few rows, the second field >>> go down (without spaces) to the next line. >>> How can I join the splitted lines? >>> For exmple: >>> I need to change the following : >>> ERROR1 1 >>> ERROR2 1 >>> WARNING1 0 >>> WARNING2 >>> 0 >>> WARNING3 >>> 0 >>> ERROR3 1 >>> To: >>> ERROR1 1 >>> ERROR2 1 >>> WARNING1 0 >>> WARNING2 0 >>> WARNING3 0 >>> ERROR3 1 >>> Thanks in advance! >> if you dont mind the whitespace: >> >> ~/superpollo$ cat fields.sh >> #!/usr/bin/env bash >> while read A B >> do >> echo -n $A" " >> if [ -z "$B" ] >> then >> read B >> echo $B >> else >> echo $B >> fi >> done >> ~/superpollo$ cat fields >> ERROR1 1 >> ERROR2 1 >> WARNING1 0 >> WARNING2 >> 0 >> WARNING3 >> 0 >> ERROR3 1 >> ~/superpollo$ ./fields.sh < fields >> ERROR1 1 >> ERROR2 1 >> WARNING1 0 >> WARNING2 0 >> WARNING3 0 >> ERROR3 1 >> ~/superpollo$ >> >> bye >> >> -- >> Il valore 96 sarebbe,Volendo, un ipercubo in i.-הסתר טקסט מצוטט- >> >> -הראה טקסט מצוטט- > > thanks! > how can I do the same in korn shell or c shell? While the proposed code is nothing I would suggest to use I also don't see that the proposed code would not run in Kornshell; have you tried? (And don't try to start using C shell for scripting.) Janis
From: superpollo on 6 Jun 2010 10:58 Janis Papanagnou ha scritto: > shulamitm wrote: >> On 6 יוני, 12:50, superpollo <ute...(a)esempio.net> wrote: >>> shulamitm ha scritto: >>> >>> >>> >>> >>> >>>> Hello, >>>> I'm looking for solution to the following problem: >>>> I have a file contains 2 fileds, but in a few rows, the second field >>>> go down (without spaces) to the next line. >>>> How can I join the splitted lines? >>>> For exmple: >>>> I need to change the following : >>>> ERROR1 1 >>>> ERROR2 1 >>>> WARNING1 0 >>>> WARNING2 >>>> 0 >>>> WARNING3 >>>> 0 >>>> ERROR3 1 >>>> To: >>>> ERROR1 1 >>>> ERROR2 1 >>>> WARNING1 0 >>>> WARNING2 0 >>>> WARNING3 0 >>>> ERROR3 1 >>>> Thanks in advance! >>> if you dont mind the whitespace: >>> >>> ~/superpollo$ cat fields.sh >>> #!/usr/bin/env bash >>> while read A B >>> do >>> echo -n $A" " >>> if [ -z "$B" ] >>> then >>> read B >>> echo $B >>> else >>> echo $B >>> fi >>> done >>> ~/superpollo$ cat fields >>> ERROR1 1 >>> ERROR2 1 >>> WARNING1 0 >>> WARNING2 >>> 0 >>> WARNING3 >>> 0 >>> ERROR3 1 >>> ~/superpollo$ ./fields.sh < fields >>> ERROR1 1 >>> ERROR2 1 >>> WARNING1 0 >>> WARNING2 0 >>> WARNING3 0 >>> ERROR3 1 >>> ~/superpollo$ >>> >>> bye >>> >>> -- >>> Il valore 96 sarebbe,Volendo, un ipercubo in i.-הסתר טקסט מצוטט- >>> >>> -הראה טקסט מצוטט- >> thanks! >> how can I do the same in korn shell or c shell? > > While the proposed code is nothing I would suggest to use can you explain why please? bye
From: Janis Papanagnou on 6 Jun 2010 11:47 superpollo wrote: > Janis Papanagnou ha scritto: >> shulamitm wrote: >>> On 6 יוני, 12:50, superpollo <ute...(a)esempio.net> wrote: >>>> shulamitm ha scritto: >>>> >>>> >>>> >>>> >>>> >>>>> Hello, >>>>> I'm looking for solution to the following problem: >>>>> I have a file contains 2 fileds, but in a few rows, the second field >>>>> go down (without spaces) to the next line. >>>>> How can I join the splitted lines? >>>>> For exmple: >>>>> I need to change the following : >>>>> ERROR1 1 >>>>> ERROR2 1 >>>>> WARNING1 0 >>>>> WARNING2 >>>>> 0 >>>>> WARNING3 >>>>> 0 >>>>> ERROR3 1 >>>>> To: >>>>> ERROR1 1 >>>>> ERROR2 1 >>>>> WARNING1 0 >>>>> WARNING2 0 >>>>> WARNING3 0 >>>>> ERROR3 1 >>>>> Thanks in advance! >>>> if you dont mind the whitespace: >>>> >>>> ~/superpollo$ cat fields.sh >>>> #!/usr/bin/env bash >>>> while read A B >>>> do >>>> echo -n $A" " >>>> if [ -z "$B" ] >>>> then >>>> read B >>>> echo $B >>>> else >>>> echo $B >>>> fi >>>> done >>>> ~/superpollo$ cat fields >>>> ERROR1 1 >>>> ERROR2 1 >>>> WARNING1 0 >>>> WARNING2 >>>> 0 >>>> WARNING3 >>>> 0 >>>> ERROR3 1 >>>> ~/superpollo$ ./fields.sh < fields >>>> ERROR1 1 >>>> ERROR2 1 >>>> WARNING1 0 >>>> WARNING2 0 >>>> WARNING3 0 >>>> ERROR3 1 >>>> ~/superpollo$ >>>> >>>> bye >>>> >>>> -- >>>> Il valore 96 sarebbe,Volendo, un ipercubo in i.-הסתר טקסט מצוטט- >>>> >>>> -הראה טקסט מצוטט- >>> thanks! >>> how can I do the same in korn shell or c shell? >> >> While the proposed code is nothing I would suggest to use > > can you explain why please? Code that has the following properties that you use I consider suspect and unreliable; 1. misleading shebang unnecessarily set to bash 2. using while/read loops 3. using read without setting IFS and option -r 4. using echo and option -n instead of printf 5. applying unquoted variables on many places 6. having lines of code duplicated unnecessarily 7. not supporting handling file arguments (silently expecting data only on stdin) Janis > > bye
From: superpollo on 7 Jun 2010 04:53 Janis Papanagnou ha scritto: > superpollo wrote: >> Janis Papanagnou ha scritto: >>> shulamitm wrote: >>>> On 6 יוני, 12:50, superpollo <ute...(a)esempio.net> wrote: >>>>> shulamitm ha scritto: >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> Hello, >>>>>> I'm looking for solution to the following problem: >>>>>> I have a file contains 2 fileds, but in a few rows, the second field >>>>>> go down (without spaces) to the next line. >>>>>> How can I join the splitted lines? >>>>>> For exmple: >>>>>> I need to change the following : >>>>>> ERROR1 1 >>>>>> ERROR2 1 >>>>>> WARNING1 0 >>>>>> WARNING2 >>>>>> 0 >>>>>> WARNING3 >>>>>> 0 >>>>>> ERROR3 1 >>>>>> To: >>>>>> ERROR1 1 >>>>>> ERROR2 1 >>>>>> WARNING1 0 >>>>>> WARNING2 0 >>>>>> WARNING3 0 >>>>>> ERROR3 1 >>>>>> Thanks in advance! >>>>> if you dont mind the whitespace: >>>>> >>>>> ~/superpollo$ cat fields.sh >>>>> #!/usr/bin/env bash >>>>> while read A B >>>>> do >>>>> echo -n $A" " >>>>> if [ -z "$B" ] >>>>> then >>>>> read B >>>>> echo $B >>>>> else >>>>> echo $B >>>>> fi >>>>> done >>>>> ~/superpollo$ cat fields >>>>> ERROR1 1 >>>>> ERROR2 1 >>>>> WARNING1 0 >>>>> WARNING2 >>>>> 0 >>>>> WARNING3 >>>>> 0 >>>>> ERROR3 1 >>>>> ~/superpollo$ ./fields.sh < fields >>>>> ERROR1 1 >>>>> ERROR2 1 >>>>> WARNING1 0 >>>>> WARNING2 0 >>>>> WARNING3 0 >>>>> ERROR3 1 >>>>> ~/superpollo$ >>>>> >>>>> bye >>>>> >>>>> -- >>>>> Il valore 96 sarebbe,Volendo, un ipercubo in i.-הסתר טקסט מצוטט- >>>>> >>>>> -הראה טקסט מצוטט- >>>> thanks! >>>> how can I do the same in korn shell or c shell? >>> While the proposed code is nothing I would suggest to use >> can you explain why please? > > Code that has the following properties that you use I consider suspect > and unreliable; > > 1. misleading shebang unnecessarily set to bash is #!/usr/bin/bash better? what should i put there instead? > 2. using while/read loops what's the alternative? > 3. using read without setting IFS and option -r is it necessary in this case? why should i do that? > 4. using echo and option -n instead of printf what's the problem with echo? > 5. applying unquoted variables on many places are unquoted vars dangerous? > 6. having lines of code duplicated unnecessarily like echo $B ? > 7. not supporting handling file arguments > (silently expecting data only on stdin) hey! it was a quickie! ;-) > Janis > >> bye thanks! bye
From: Janis Papanagnou on 7 Jun 2010 07:52 superpollo schrieb: > Janis Papanagnou ha scritto: >> superpollo wrote: >>> Janis Papanagnou ha scritto: >>>> shulamitm wrote: >>>>> On 6 יוני, 12:50, superpollo <ute...(a)esempio.net> wrote: >>>>>> shulamitm ha scritto: >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> Hello, >>>>>>> I'm looking for solution to the following problem: >>>>>>> I have a file contains 2 fileds, but in a few rows, the second field >>>>>>> go down (without spaces) to the next line. >>>>>>> How can I join the splitted lines? >>>>>>> For exmple: >>>>>>> I need to change the following : >>>>>>> ERROR1 1 >>>>>>> ERROR2 1 >>>>>>> WARNING1 0 >>>>>>> WARNING2 >>>>>>> 0 >>>>>>> WARNING3 >>>>>>> 0 >>>>>>> ERROR3 1 >>>>>>> To: >>>>>>> ERROR1 1 >>>>>>> ERROR2 1 >>>>>>> WARNING1 0 >>>>>>> WARNING2 0 >>>>>>> WARNING3 0 >>>>>>> ERROR3 1 >>>>>>> Thanks in advance! >>>>>> if you dont mind the whitespace: >>>>>> >>>>>> ~/superpollo$ cat fields.sh >>>>>> #!/usr/bin/env bash >>>>>> while read A B >>>>>> do >>>>>> echo -n $A" " >>>>>> if [ -z "$B" ] >>>>>> then >>>>>> read B >>>>>> echo $B >>>>>> else >>>>>> echo $B >>>>>> fi >>>>>> done >>>>>> ~/superpollo$ cat fields >>>>>> ERROR1 1 >>>>>> ERROR2 1 >>>>>> WARNING1 0 >>>>>> WARNING2 >>>>>> 0 >>>>>> WARNING3 >>>>>> 0 >>>>>> ERROR3 1 >>>>>> ~/superpollo$ ./fields.sh < fields >>>>>> ERROR1 1 >>>>>> ERROR2 1 >>>>>> WARNING1 0 >>>>>> WARNING2 0 >>>>>> WARNING3 0 >>>>>> ERROR3 1 >>>>>> ~/superpollo$ >>>>>> >>>>>> bye >>>>>> >>>>>> -- >>>>>> Il valore 96 sarebbe,Volendo, un ipercubo in i.-הסתר טקסט מצוטט- >>>>>> >>>>>> -הראה טקסט מצוטט- >>>>> thanks! >>>>> how can I do the same in korn shell or c shell? >>>> While the proposed code is nothing I would suggest to use >>> can you explain why please? >> >> Code that has the following properties that you use I consider suspect >> and unreliable; >> >> 1. misleading shebang unnecessarily set to bash > > is #!/usr/bin/bash better? what should i put there instead? If you're using just standard shell features without relying on any bash'isms I'd suggest specify just that; standard sh. Especially if the OP hasn't asked for a specific shell it's better to not assume that he has a bash on his system, and to not give the impression that bash would be required to execute your code. > >> 2. using while/read loops > > what's the alternative? Any tool that does the loop implicitly. I wouldn't want to say here that you should use something else, but code with while/read loops are at least suspicious; in many cases it has been pointed out here that this construct turned out to be inferior. > >> 3. using read without setting IFS and option -r > > is it necessary in this case? why should i do that? The bourne shell family of shells show some often unwanted behaviour WRT interpreting special characters and handling of field-splitting/ whitespace characters if used in default mode, and you need to take some actions to handle it as needed. Those two details are typical; this is regularily explained here, you may look that up if you missed it. > >> 4. using echo and option -n instead of printf > > what's the problem with echo? As well regularily explained here, and certainly also in the FAQ. > >> 5. applying unquoted variables on many places > > are unquoted vars dangerous? Usually, yes. Similar to point 3; the default behaviour of unquoted variable expansion is not well designed in the bourne shell family. As a rule of thumb; always quote your variables, this is what you really want in most cases. > >> 6. having lines of code duplicated unnecessarily > > like echo $B ? Yes. It's trivial, I know, but I've added it since I was writing up that list anyway, so I thought it couldn't hurt mentioning it. > >> 7. not supporting handling file arguments >> (silently expecting data only on stdin) > > hey! it was a quickie! ;-) Sure. But since you asked. :-) The point is that a couple tools already do that implicitly. If you considered above point 2. you might as well have it already handled implicitly. Janis > >> Janis >> >>> bye > > thanks! > > bye
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: vpath w/implicit pattern rule, & non-basename target (GNU make) Next: grepping from last file of a listing...... |