[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:
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 .
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:
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 ..
You could try something like this:
sed -e 's/{/\n{/' -e s'/}/}\n/'
On Monday 19 September 2011 09:17:02 Per Jessen wrote:
Peter Nikolic wrote:
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 ..
You could try something like this:
sed -e 's/{/\n{/' -e s'/}/}\n/'
(not sure if you need to escape the curly brackets).
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:
On Monday 19 September 2011 09:17:02 Per Jessen wrote:
Peter Nikolic wrote:
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 ..
You could try something like this:
sed -e 's/{/\n{/' -e s'/}/}\n/'
(not sure if you need to escape the curly brackets).
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 .
Hi Peter
this is better:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g'
Hello, On Mon, 19 Sep 2011, Per Jessen wrote:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g'
(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'
David Haller wrote:
Hello,
On Mon, 19 Sep 2011, Per Jessen wrote:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g'
(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).
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:
David Haller wrote:
On Mon, 19 Sep 2011, Per Jessen wrote:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g'
(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).
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 ?
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
David Haller wrote:
Hello,
On Tue, 20 Sep 2011, Per Jessen wrote:
David Haller wrote:
On Mon, 19 Sep 2011, Per Jessen wrote:
sed -e 's/{/\n{/g' -e s'/}/}\n/g' -e s'/;/;\n/g'
(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).
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 ?
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).
With sed, I always need to escape +() inside '' to get them to work. Am I doing something wrong? -- Per Jessen, Zürich (13.9°C) -- 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:
David Haller 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).
With sed, I always need to escape +() inside '' to get them to work. Am I doing something wrong?
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:
Hello,
On Thu, 22 Sep 2011, Per Jessen wrote:
David Haller 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).
With sed, I always need to escape +() inside '' to get them to work. Am I doing something wrong?
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
Ah, that explains it. Thanks. -- Per Jessen, Zürich (15.7°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David Haller wrote: [snip]
Depends on what meaning you want the +() to have. [snip] 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 ;)
[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:
David Haller wrote: [..]
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 ;)
[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!
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 --
What is that fluff that persistantly gathers in the bottom corner of my wardrobe? And in response, thus spake the Oracle: } Moths that died laughing. [#1350-05] -- 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