LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-24-2019, 11:13 AM   #1
tlillenuit
LQ Newbie
 
Registered: Mar 2019
Posts: 12

Rep: Reputation: Disabled
Sed formatting


I redirected the output of ls -lh $ZSH/themes to the file themeslist
and want to extract only pure themes names list to get them prepared for insertion into my .zshrc, but formatted as per:

#3den
#abden
#af-magic
#afowler
#agnoster (and so on)

How do I do this using sed - how do I get rid of all the excessive elements? Thanks!

-rw-rw-r-- 1 tlil tlil 330 Mar 24 15:10 3den.zsh-theme
-rw-rw-r-- 1 tlil tlil 4.5K Mar 24 15:10 adben.zsh-theme
-rw-rw-r-- 1 tlil tlil 986 Mar 24 15:10 af-magic.zsh-theme
-rw-rw-r-- 1 tlil tlil 394 Mar 24 15:10 afowler.zsh-theme
-rw-rw-r-- 1 tlil tlil 7.2K Mar 24 15:10 agnoster.zsh-theme
-rw-rw-r-- 1 tlil tlil 1.1K Mar 24 15:10 alanpeabody.zsh-theme
-rw-rw-r-- 1 tlil tlil 748 Mar 24 15:10 amuse.zsh-theme
-rw-rw-r-- 1 tlil tlil 822 Mar 24 15:10 apple.zsh-theme
-rw-rw-r-- 1 tlil tlil 506 Mar 24 15:10 arrow.zsh-theme
-rw-rw-r-- 1 tlil tlil 325 Mar 24 15:10 aussiegeek.zsh-theme
-rw-rw-r-- 1 tlil tlil 3.4K Mar 24 15:10 avit.zsh-theme
-rw-rw-r-- 1 tlil tlil 750 Mar 24 15:10 awesomepanda.zsh-theme
-rw-rw-r-- 1 tlil tlil 980 Mar 24 15:10 bira.zsh-theme
-rw-rw-r-- 1 tlil tlil 979 Mar 24 15:10 blinks.zsh-theme
-rw-rw-r-- 1 tlil tlil 3.3K Mar 24 15:10 bureau.zsh-theme
-rw-rw-r-- 1 tlil tlil 1.2K Mar 24 15:10 candy-kingdom.zsh-theme
-rw-rw-r-- 1 tlil tlil 365 Mar 24 15:10 candy.zsh-theme
-rw-rw-r-- 1 tlil tlil 1.3K Mar 24 15:10 clean.zsh-theme
-rw-rw-r-- 1 tlil tlil 476 Mar 24 15:10 cloud.zsh-theme
-rw-rw-r-- 1 tlil tlil 372 Mar 24 15:10 crcandy.zsh-theme
-rw-rw-r-- 1 tlil tlil 1.9K Mar 24 15:10 crunch.zsh-theme
-rw-rw-r-- 1 tlil tlil 262 Mar 24 15:10 cypher.zsh-theme
 
Old 03-24-2019, 01:43 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Code:
 cat awk-themes | awk '{print "#"$9}' | sed 's|\.[a-z].*||'
#3den
#adben
#af-magic
#afowler
#agnoster
#alanpeabody
#amuse
'awk-themes' That is what I named the file, if you want to put that output into another file just redirect it into it.

Last edited by BW-userx; 03-24-2019 at 01:58 PM.
 
1 members found this post helpful.
Old 03-24-2019, 02:04 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,726

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
I'd have started with
Code:
ls -1 $ZSH/themes
(that's a one, not an ell) which would have put
Code:
3den.zsh-theme
adben.zsh-theme
af-magic.zsh-theme
afowler.zsh-theme
agnoster.zsh-theme
...
in your output file, then
Code:
sed -e 's/^/#/' -e 's/.zsh-theme//' themeslist
Or, all at once:
Code:
ls -1 $ZSH/themes | sed -e 's/^/#/' -e 's/.zsh-theme//' > themeslist
where themeslist is list as requested for insertion.
 
Old 03-24-2019, 06:29 PM   #4
tlillenuit
LQ Newbie
 
Registered: Mar 2019
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thank you! Isn't this marvelous? Sed and awk the real power things!
 
Old 03-25-2019, 05:41 AM   #5
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748
Just for fun, a bash one-liner
Code:
for f in *.zsh-theme; do [[ "$f" =~ ([[:alnum:]]+).zsh-theme ]] && echo "#${BASH_REMATCH[1]}"; done
 
1 members found this post helpful.
Old 03-25-2019, 01:03 PM   #6
tlillenuit
LQ Newbie
 
Registered: Mar 2019
Posts: 12

Original Poster
Rep: Reputation: Disabled
Lads, could you please point me to some good materials where I could learn those things in-depth? I mean, sed, awk, (ba)sh power tricks... Thanks a million!
 
Old 03-25-2019, 01:10 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,296
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
I recommend these:

Wooledge's Bash Guide
Wooledge's Bash Pitfalls
Wooledge's Bash Frequently Asked Questions
The Bash Hackers' Wiki

Bruce Barnett' AWK Grymoire

Bruce Barnett' sed Grymoire
sed One-Liners Explained

It's a matter of figuring out what each tool is best at and where to look up the details.
 
2 members found this post helpful.
Old 03-30-2019, 08:47 AM   #8
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Rep: Reputation: 15
it'd be simple for no space name;
Code:
ls -lh $ZSH/themes |sed -E 's/^.*\s(\S+)-theme$/\1/i'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash / Sed - Text conversion, to fix formatting for ascii art mac101 Programming 3 10-06-2014 11:54 AM
[SOLVED] Formatting data with Sed and Awk itachi8009 Programming 10 08-06-2013 10:32 AM
Formatting Help needed(Sed) pinga123 Linux - Newbie 3 06-22-2010 11:46 AM
Using awk/sed to convert linefeed to csv, with some formatting jaykup Programming 1 04-03-2009 05:18 PM
sed or other formatting command help SeT Linux - General 1 10-13-2004 06:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration