LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-18-2010, 10:56 PM   #1
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
Omit specified characters from the output of a command


After typing "man cut" in my terminal I can't seem to find this answer.

I am trying to write several shell scripts and want to remove the 'lp:<package name>' from the beginning of each line of the output of "bzr ls" as well as any notices at the beginning of the output, leaving only file and folder paths.

However, I can't seem to figure out how to do it. Can anybody help me?

Last edited by Kenny_Strawn; 11-18-2010 at 11:20 PM.
 
Old 11-19-2010, 01:00 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
I don't have bzr on my system. If you post some of the command's output, I might be able to help.
 
Old 11-19-2010, 01:30 AM   #3
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791

Original Poster
Blog Entries: 62

Rep: Reputation: 56
This is the full output of 'bzr ls -R lp:unity', for example:

Code:
lp:unity/.bzrignore
lp:unity/AUTHORS
lp:unity/CMakeLists.txt
lp:unity/COPYING
lp:unity/COPYING.LGPL
lp:unity/ChangeLog
lp:unity/README
lp:unity/cmake/
lp:unity/cmake/vala/
lp:unity/cmake/vala/FindVala.cmake
lp:unity/cmake/vala/ParseArguments.cmake
lp:unity/cmake/vala/README.rst
lp:unity/cmake/vala/ValaPrecompile.cmake
lp:unity/cmake/vala/ValaVersion.cmake
lp:unity/com.canonical.Unity.gschema.xml
lp:unity/config.h.cmake
lp:unity/libunity/
lp:unity/libunity/CMakeLists.txt
lp:unity/libunity/chrome-handler.vala
lp:unity/libunity/drag-controller.vala
lp:unity/libunity/drag-view.vala
lp:unity/libunity/entry.vala
lp:unity/libunity/icon-postprocessor.vala
lp:unity/libunity/prism-handler.vala
lp:unity/libunity/quicklist-rendering.vala
lp:unity/libunity/shell.vala
lp:unity/libunity/theme.vala
lp:unity/libunity/unity-appinfo-manager.vala
lp:unity/libunity/unity-cairo-canvas.vala
lp:unity/libunity/unity-expanding-bin.vala
lp:unity/libunity/unity-favorites.vala
lp:unity/libunity/unity-io.vala
lp:unity/libunity/unity-layered-bin.vala
lp:unity/libunity/unity-pixbuf-cache.vala
lp:unity/libunity/unity-place-activation.vala
lp:unity/libunity/unity-place-browser.vala
lp:unity/libunity/unity-place-renderer.vala
lp:unity/libunity/unity-place.vala
lp:unity/libunity/unity-stripe-texture.vala
lp:unity/libunity/unity.pc.cmake
lp:unity/libunity/webapp-fetcher.vala
lp:unity/po/
lp:unity/po/LINGUAS
lp:unity/po/POTFILES.in
lp:unity/po/POTFILES.skip
lp:unity/po/ar.po
lp:unity/po/bg.po
lp:unity/po/cs.po
lp:unity/po/da.po
lp:unity/po/de.po
lp:unity/po/el.po
lp:unity/po/es.po
lp:unity/po/fi.po
lp:unity/po/fr.po
lp:unity/po/he.po
lp:unity/po/hi.po
lp:unity/po/hr.po
lp:unity/po/hu.po
lp:unity/po/it.po
lp:unity/po/ja.po
lp:unity/po/ko.po
lp:unity/po/nb.po
lp:unity/po/nl.po
lp:unity/po/pl.po
lp:unity/po/pt.po
lp:unity/po/pt_BR.po
lp:unity/po/ro.po
lp:unity/po/ru.po
lp:unity/po/sk.po
lp:unity/po/sl.po
lp:unity/po/sr.po
lp:unity/po/sv.po
lp:unity/po/th.po
lp:unity/po/tr.po
lp:unity/po/unity.pot
lp:unity/po/zh_CN.po
lp:unity/po/zh_TW.po
lp:unity/resources/
lp:unity/resources/2indicate_54x54.png
lp:unity/resources/3indicate_54x54.png
lp:unity/resources/4indicate_54x54.png
lp:unity/resources/bfb.png
lp:unity/resources/focused_indicator.png
lp:unity/resources/round_corner_50x50.png
lp:unity/resources/round_corner_54x54.png
lp:unity/resources/round_outline_50x50.png
lp:unity/resources/round_outline_54x54.png
lp:unity/resources/round_shine_54x54.png
lp:unity/resources/running_indicator.png
lp:unity/services/
lp:unity/services/CMakeLists.txt
lp:unity/services/com.canonical.Unity.Panel.Service.service.cmake
lp:unity/services/panel-main.c
lp:unity/services/panel-service.c
lp:unity/services/panel-service.h
lp:unity/src/
lp:unity/src/BamfLauncherIcon.cpp
lp:unity/src/BamfLauncherIcon.h
lp:unity/src/FavoriteStore.cpp
lp:unity/src/FavoriteStore.h
lp:unity/src/FavoriteStoreGSettings.cpp
lp:unity/src/FavoriteStoreGSettings.h
lp:unity/src/IndicatorObjectEntryProxy.h
lp:unity/src/IndicatorObjectEntryProxyRemote.cpp
lp:unity/src/IndicatorObjectEntryProxyRemote.h
lp:unity/src/IndicatorObjectFactory.h
lp:unity/src/IndicatorObjectFactoryRemote.cpp
lp:unity/src/IndicatorObjectFactoryRemote.h
lp:unity/src/IndicatorObjectProxy.h
lp:unity/src/IndicatorObjectProxyRemote.cpp
lp:unity/src/IndicatorObjectProxyRemote.h
lp:unity/src/Launcher.cpp
lp:unity/src/Launcher.h
lp:unity/src/LauncherController.cpp
lp:unity/src/LauncherController.h
lp:unity/src/LauncherIcon.cpp
lp:unity/src/LauncherIcon.h
lp:unity/src/LauncherModel.cpp
lp:unity/src/LauncherModel.h
lp:unity/src/PanelHomeButton.cpp
lp:unity/src/PanelHomeButton.h
lp:unity/src/PanelIndicatorObjectEntryView.cpp
lp:unity/src/PanelIndicatorObjectEntryView.h
lp:unity/src/PanelIndicatorObjectView.cpp
lp:unity/src/PanelIndicatorObjectView.h
lp:unity/src/PanelView.cpp
lp:unity/src/PanelView.h
lp:unity/src/PluginAdapter.cpp
lp:unity/src/PluginAdapter.h
lp:unity/src/QuicklistView.cpp
lp:unity/src/QuicklistView.h
lp:unity/src/SimpleLauncherIcon.cpp
lp:unity/src/SimpleLauncherIcon.h
lp:unity/src/StaticCairoText.cpp
lp:unity/src/StaticCairoText.h
lp:unity/src/Tooltip.cpp
lp:unity/src/Tooltip.h
lp:unity/src/unity.cpp
lp:unity/src/unity.h
lp:unity/tests/
lp:unity/tests/CMakeLists.txt
lp:unity/tests/TestPanel.cpp
lp:unity/tests/unit/
lp:unity/tests/unit/TestFavoriteStoreGSettings.cpp
lp:unity/tests/unit/TestMain.cpp
lp:unity/tests/unit/TestPanelService.cpp
lp:unity/tools/
lp:unity/tools/build-compiz-glib
lp:unity/tools/makebootchart.py
lp:unity/tools/migrate_favorites.py
lp:unity/unity-private/
lp:unity/unity-private/application.vala
lp:unity/unity-private/gesture/
lp:unity/unity-private/gesture/gesture-dispatcher-xcb-glu.vala
lp:unity/unity-private/gesture/gesture-dispatcher-xcb-glue.c
lp:unity/unity-private/gesture/gesture-dispatcher-xcb.vala
lp:unity/unity-private/gesture/gesture-dispatcher.vala
lp:unity/unity-private/gesture/gesture-event.vala
lp:unity/unity-private/gesture/gesture.c
lp:unity/unity-private/gesture/gesture.h
lp:unity/unity-private/launcher/
lp:unity/unity-private/launcher/application-controller.vala
lp:unity/unity-private/launcher/launcher.vala
lp:unity/unity-private/launcher/quicklist-check-menu-item.vala
lp:unity/unity-private/launcher/quicklist-controller.vala
lp:unity/unity-private/launcher/quicklist-image-menu-item.vala
lp:unity/unity-private/launcher/quicklist-menu-item.vala
lp:unity/unity-private/launcher/quicklist-radio-menu-item.vala
lp:unity/unity-private/launcher/quicklist-seperator-menu-item.vala
lp:unity/unity-private/launcher/quicklist-view.vala
lp:unity/unity-private/launcher/scroller-controller.vala
lp:unity/unity-private/launcher/scroller-model.vala
lp:unity/unity-private/launcher/scroller-view.vala
lp:unity/unity-private/launcher/scrollerchild-controller.vala
lp:unity/unity-private/launcher/scrollerchild.vala
lp:unity/unity-private/panel/
lp:unity/unity-private/panel/panel-background.vala
lp:unity/unity-private/panel/panel-divider.vala
lp:unity/unity-private/panel/panel-home-button.vala
lp:unity/unity-private/panel/panel-indicator-background.vala
lp:unity/unity-private/panel/panel-indicator-bar.vala
lp:unity/unity-private/panel/panel-indicator-model.vala
lp:unity/unity-private/panel/panel-indicator-object-entry-view.vala
lp:unity/unity-private/panel/panel-indicator-object-view.vala
lp:unity/unity-private/panel/panel-menu-manager.vala
lp:unity/unity-private/panel/panel-menubar.vala
lp:unity/unity-private/panel/panel-tray.vala
lp:unity/unity-private/panel/panel-view.vala
lp:unity/unity-private/panlp:unity/unity-private/places/
lp:unity/unity-private/places/places-button.vala
lp:unity/unity-private/places/places-controller.vala
lp:unity/unity-private/places/places-default-renderer-group.vala
lp:unity/unity-private/places/places-default-renderer-tiles.vala
lp:unity/unity-private/places/places-default-renderer.vala
lp:unity/unity-private/places/places-folder-browser-renderer.vala
lp:unity/unity-private/places/places-place-bar.vala
lp:unity/unity-private/places/places-place-entry-scroller-child.vala
lp:unity/unity-private/places/places-place-entry-view.vala
lp:unity/unity-private/places/places-place-entry.vala
lp:unity/unity-private/places/places-place-home-renderer.vala
lp:unity/unity-private/places/places-place-home.vala
lp:unity/unity-private/places/places-place-model.vala
lp:unity/unity-private/places/places-place-search-bar.vala
lp:unity/unity-private/places/places-place-search-entry.vala
lp:unity/unity-private/places/places-place-search-extra-action.vala
lp:unity/unity-private/places/places-place-search-navigation.vala
lp:unity/unity-private/places/places-place-search-sections-bar.vala
lp:unity/unity-private/places/places-place-view.vala
lp:unity/unity-private/places/places-place.vala
lp:unity/unity-private/places/places-trash-controller.vala
lp:unity/unity-private/places/places-view.vala
lp:unity/unity-private/places/places-volume-child-controller.vala
lp:unity/unity-private/places/places-volume-controller.vala
lp:unity/unity-private/testing/
lp:unity/unity-private/testing/background.vala
lp:unity/unity-private/testing/object-registry.vala
lp:unity/unity-private/testing/perf-logger.vala
lp:unity/unity-private/testing/test-director.vala
lp:unity/unity-private/testing/test-utils.vala
lp:unity/unity-private/testing/test-window.vala
lp:unity/unity-private/unity-quirks.vala
lp:unity/unity-private/unity-utils.c
lp:unity/unity-private/unity-utils.h
lp:unity/unity-private/unity.vala
lp:unity/unity-private/utils.vala
lp:unity/unityshell.xml.in
lp:unity/vala_tests/
lp:unity/vala_tests/ui/
lp:unity/vala_tests/ui/Makefile.am
lp:unity/vala_tests/ui/data/
lp:unity/vala_tests/ui/data/Makefile.am
lp:unity/vala_tests/ui/data/quicklist_controller_show_label.png
lp:unity/vala_tests/ui/data/quicklist_shown_on_hover.png
lp:unity/vala_tests/ui/test-automate.vala
lp:unity/vala_tests/ui/test-const.vapi
lp:unity/vala_tests/ui/test-home-button.vala
lp:unity/vala_tests/ui/test-indicators.vala
lp:unity/vala_tests/ui/test-quicklist.vala
lp:unity/vala_tests/ui/test-ui.vala
lp:unity/vala_tests/unit/
lp:unity/vala_tests/unit/Makefile.am
lp:unity/vala_tests/unit/data/
lp:unity/vala_tests/unit/data/Makefile.am
lp:unity/vala_tests/unit/data/applications/
lp:unity/vala_tests/unit/data/applications/ubuntu-about.desktop
lp:unity/vala_tests/unit/data/place0.badplace
lp:unity/vala_tests/unit/data/place0.place
lp:unity/vala_tests/unit/data/place1.badplace
lp:unity/vala_tests/unit/data/place1.place
lp:unity/vala_tests/unit/data/test_desktop_file.desktop
lp:unity/vala_tests/unit/test-appinfo-manager.vala
lp:unity/vala_tests/unit/test-const.vapi
lp:unity/vala_tests/unit/test-dbusmenu-quicklists.vala
lp:unity/vala_tests/unit/test-io.vala
lp:unity/vala_tests/unit/test-launcher.vala
lp:unity/vala_tests/unit/test-panel-indicator-object-entry-view.vala
lp:unity/vala_tests/unit/test-panel-indicator-object-view.vala
lp:unity/vala_tests/unit/test-place-browser.vala
lp:unity/vala_tests/unit/test-place.vala
lp:unity/vala_tests/unit/test-places-place-file-model.vala
lp:unity/vala_tests/unit/test-places-place.vala
lp:unity/vala_tests/unit/test-places.vala
lp:unity/vala_tests/unit/test-unit.vala
lp:unity/vala_tests/unit/test-unity-pixbuf-cache.vala
lp:unity/vapi/
lp:unity/vapi/Makefile.am
lp:unity/vapi/config.vapi
lp:unity/vapi/dee-1.0.deps
lp:unity/vapi/dee-1.0.vapi
lp:unity/vapi/unity-const.vapi
I want to be able to cut out the 'lp:unity' from the beginning of every line.

This is just a test of the command, though; I really am creating a shell script and the data bzr is operating on in the script is a variable.

Last edited by Kenny_Strawn; 11-19-2010 at 01:32 AM. Reason: Removed unnecessary newlines in output of command
 
Old 11-19-2010, 02:15 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
echo "$var" | awk '/^lp:unity/{sub(/^lp:unity/,""); print}'
where var contains the output of bzr ls. This also removes any header line, provided that only the ones you want to keep begin with "lp:unity".
 
Old 11-19-2010, 02:52 AM   #5
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791

Original Poster
Blog Entries: 62

Rep: Reputation: 56
Okay, thank you.
 
Old 11-19-2010, 03:12 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
If you are certain the output looks as in post #3 for all lines:
Code:
bzr ls -R lp:unity | cut -c9-
 
Old 11-19-2010, 04:07 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Kenny_Strawn View Post
After typing "man cut" in my terminal I can't seem to find this answer.
...
How about first answering the question: "What is the delimiter I am going to use in 'cut' command ?" ?

The relevant excerpt is:

Code:
      1 CUT(1)                                                                      User Commands                                                                     CUT
      1 (1)
      2
      3
      4
      5 NAME
      6        cut - remove sections from each line of files
      7
      8 SYNOPSIS
      9        cut OPTION... [FILE]...
     10
     11 DESCRIPTION
     12        Print selected parts of lines from each FILE to standard output.
     13
     14        Mandatory arguments to long options are mandatory for short options too.
     15
     16        -b, --bytes=LIST
     17               select only these bytes
     18
     19        -c, --characters=LIST
     20               select only these characters
     21
     22        -d, --delimiter=DELIM
     23               use DELIM instead of TAB for field delimiter
, so, did you read the very first 23 lines of the manpage, and the 23 lines include blank lines too.
 
  


Reply

Tags
cut, omit+characters



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Repeatedly getting command substitution: line 3: syntax error near unexpected token dontob Linux - General 8 08-31-2010 08:26 AM
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 12:46 PM
shell script: saving output from command into a variable grcunning Linux - Newbie 7 01-26-2010 11:43 AM
[shell script] execute command and parse output stoiss Programming 2 01-26-2009 01:49 AM
Help!! Shell script to get output of ls -l command into an array kasthana Programming 8 06-01-2008 11:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:29 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