[opensuse] Java script assistance (slightly OT)

Hi . This is slightly OT but not too bad i hope . I have a numbver of .js files that are strung out in one huge line of text they are a real pain to do anything with and take an age to load and edit Is there a way other than sitting ther and manually sorting the of doing it automatically .. Pete . -- Powered by openSUSE 11.3 (x86_64) Kernel: 2.6.34.10-0.2-desktop KDE Development Platform: 4.6.00 (4.6.0) 20:45 up 15 days 2:15, 4 users, load average: 0.13, 0.11, 0.09 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

On 18/09/11 20:47, Peter Nikolic wrote:
Try this: http://jsbeautifier.org/ Regards, Tejas -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Peter Nikolic wrote:
You could try something like this: sed -e 's/{/\n{/' -e s'/}/}\n/' <filename (not sure if you need to escape the curly brackets). -- Per Jessen, Zürich (10.4°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

On Monday 19 September 2011 09:17:02 Per Jessen wrote:
Hi Per Thanks i will give it a whirl later see what happens on a copy of the file i have seen the online systems but the darn file takes so long to load into an editor or just do a less on that i cant C&P it across real pain . I have had the same problem with html files from this old club site built by website builder one huge long line of text terrible things. Pete . -- Powered by openSUSE 11.3 (x86_64) Kernel: 2.6.34.10-0.2-desktop KDE Development Platform: 4.6.00 (4.6.0) 14:32 up 15 days 20:02, 4 users, load average: 0.05, 0.04, 0.02 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Peter Nikolic wrote:
Hi Peter this is better: sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g' <filename (still not sure if you need to escape the curly brackets). -- Per Jessen, Zürich (11.6°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Hello, On Mon, 19 Sep 2011, Per Jessen wrote:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g' <filename
(still not sure if you need to escape the curly brackets).
You don't, as sed uses basic regular expressions (see 'man 7 regex'), so you need to escape {} to get "special" behaviour (if any). And you don't need to use -e for each expression, just use: sed -e 's/{/\n{/g; s/}/}\n/g; s/;/;\n/g' <filename or more readble: sed -e 's/{/\n{/g; s/}/}\n/g; s/;/;\n/g' <filename Albeit, there are some rare cases where you do need to use '-e' multiple times, IIRC when one expression has to work on the result(!) of a previous expression, but apparently GNU sed 4.2.1 has got that fixed. Oh, and JFTR: not every sed handles '\n'! E.g. GNU sed up until a few years ago (at least a 10yr old one didn't). In those cases, you have to embed the (masked by backslash) linebreaks literally: sed -e 's/{/\ {/g; s/}/}\ /g; s/;/;\ /g' <filename BTW: I prefer the linebreak after the '{' of a block, i.e.: sed -e 's/{/{\n/g; s/}/}\n/g; s/;/;\n/g' HTH, -dnh -- Unsubscribing from a mailing list you subscribed to is a basic IQ test for Internet users. -- Author unknown, seen on the PCR-1000 list -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

David Haller wrote:
Okay, but I was more thinking of escaping for the shell - for instance, when you use () for grouping, they need to be escaped to work. Which I think(!) is a shell issue, not sed ? -- Per Jessen, Zürich (10.4°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Hello, On Tue, 20 Sep 2011, Per Jessen wrote:
Inside '' you only need to escape ' itself, which doesn't work, as \ has no special meaning either inside of ''. Workaround: 'foo'"'"'bar' or 'foo'\''bar' Inside "" you have to IIRC escape !"()`` and $ (the ! only if you've enabled history substitution (set -H). HTH, -dnh -- "Spies hide guns like squirrels hide acorns." -- Burn Notice, 1x12 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Hello, On Thu, 22 Sep 2011, Per Jessen wrote:
Depends on what meaning you want the +() to have. Read 'man 7 regex'. As stated, sed uses basic regex, i.e. +() have no special meaning (when sed sees them, use 'set -x' to find out what sed actually gets). If you want to have them special meaning (grouping for () and "once or more often"), then you need to escape them _for sed_ (see man 7 regex). Mind you: that "escaping for sed" is completely seperated from "escaping in the shell". E.g.: sed s/\\\(.\\\)/X\\\1/g == sed "s/\(.\)/X\1/g" ### remember what you need to escape from ### the shell inside the "" though! == sed 's/\(.\)/X\1/g' != sed 's/(.)/X\1/g' => ERROR: "invalid reference \1 on `s' command's RHS" (there is no "grouping" on the LHS). With '\+' it's analoguous (and \+ is not portable, IIRC, but available in GNU sed for at least 10 years, I think). Again: 'man 7 regex' should clear up most of your misunderstandings. But feel free to ask for further clarifications / explanations (esp. where shell quoting/escaping is involved, that can get quite confusing ;) Ah, while trying to understand 'man 7 regex' _DO_ 'set -x', to see what sed (or grep for that matter) actually get passed from the shell. If you don't, you might get confused by "what's escaped from the shell and what for sed/grep ... Oh, and BTW: within a .spec file it's another level of "fun" added ;P Extra fun, if you "live-patch" a Makefile from a .spec. That's yet another level[1] :) So, the guideline (to use a patch) is a good thing! HTH, -dnh [1] but quite satisfying, once you "get" to work. BTDT. -- Kid, you've got the attention span of a caffeinated hummingbird. -- "Hammer" to "Kid" in Angels 2200 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

David Haller wrote: [snip]
[snip] If you don't, you might get confused by "what's escaped from
the shell and what for sed/grep ...
This reminds me of why I like Perl. Sure its ugly and complicated but at least its just one sort of ugly for everything! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Hello, On Thu, 22 Sep 2011, Dave Howorth wrote:
There's an easy workaround: use sed- or awk-scripts. E.g.: ,----[ ~/bin/delcomments ] | #!/usr/bin/sed -f | /^[[:space:]]*#/d | /^[[:space:]]*$/d `---- or ,----[ ~/bin/headntail ] | #!/usr/bin/gawk -f [..] `---- No worries about escaping/quoting in those scripts ;) To be fair, you'd have to compare to 'perl -e' oneliners. And you get the same problems there re quoting/escaping as with sed or awk. Put the stuff into a file and run that, I'm a happy bunny, whether using sed, awk or perl. I do prefer perl most of the time, esp. with a 'system' wrapper ;) -dnh --

On 18/09/11 20:47, Peter Nikolic wrote:
Try this: http://jsbeautifier.org/ Regards, Tejas -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Peter Nikolic wrote:
You could try something like this: sed -e 's/{/\n{/' -e s'/}/}\n/' <filename (not sure if you need to escape the curly brackets). -- Per Jessen, Zürich (10.4°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

On Monday 19 September 2011 09:17:02 Per Jessen wrote:
Hi Per Thanks i will give it a whirl later see what happens on a copy of the file i have seen the online systems but the darn file takes so long to load into an editor or just do a less on that i cant C&P it across real pain . I have had the same problem with html files from this old club site built by website builder one huge long line of text terrible things. Pete . -- Powered by openSUSE 11.3 (x86_64) Kernel: 2.6.34.10-0.2-desktop KDE Development Platform: 4.6.00 (4.6.0) 14:32 up 15 days 20:02, 4 users, load average: 0.05, 0.04, 0.02 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Peter Nikolic wrote:
Hi Peter this is better: sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g' <filename (still not sure if you need to escape the curly brackets). -- Per Jessen, Zürich (11.6°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

Hello, On Mon, 19 Sep 2011, Per Jessen wrote:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g' <filename
(still not sure if you need to escape the curly brackets).
You don't, as sed uses basic regular expressions (see 'man 7 regex'), so you need to escape {} to get "special" behaviour (if any). And you don't need to use -e for each expression, just use: sed -e 's/{/\n{/g; s/}/}\n/g; s/;/;\n/g' <filename or more readble: sed -e 's/{/\n{/g; s/}/}\n/g; s/;/;\n/g' <filename Albeit, there are some rare cases where you do need to use '-e' multiple times, IIRC when one expression has to work on the result(!) of a previous expression, but apparently GNU sed 4.2.1 has got that fixed. Oh, and JFTR: not every sed handles '\n'! E.g. GNU sed up until a few years ago (at least a 10yr old one didn't). In those cases, you have to embed the (masked by backslash) linebreaks literally: sed -e 's/{/\ {/g; s/}/}\ /g; s/;/;\ /g' <filename BTW: I prefer the linebreak after the '{' of a block, i.e.: sed -e 's/{/{\n/g; s/}/}\n/g; s/;/;\n/g' HTH, -dnh -- Unsubscribing from a mailing list you subscribed to is a basic IQ test for Internet users. -- Author unknown, seen on the PCR-1000 list -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org

David Haller wrote:
Okay, but I was more thinking of escaping for the shell - for instance, when you use () for grouping, they need to be escaped to work. Which I think(!) is a shell issue, not sed ? -- Per Jessen, Zürich (10.4°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (5)
-
Dave Howorth
-
David Haller
-
Per Jessen
-
Peter Nikolic
-
Tejas Guruswamy