AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-1171902

Yunfei Chen's questions

Martin Hope
Yunfei Chen
Asked: 2021-07-02 15:30:38 +0800 CST

在for循环bash中使用变量[重复]

  • 0
这个问题在这里已经有了答案:
使用用户输入来确定 for 循环迭代的次数 1 个答案
去年关闭。

我只是想知道是否可以在 for 循环中使用变量?我试过了:

for number in { eval echo {0..$1}}
do 
    echo 5
done

我的意思是让它打印出我输入提示的次数 5 但是,如果我输入,它的行为会很奇怪:

./test.sh 2

它应该打印 5 两次,但它会打印 5 四次。有人可以帮我弄这个吗?还有为什么它打印了 4 次而不是 2 次?

编辑:大部分

for number in $(seq "$2")

有效,但如果我尝试用它进行计算,它会破坏我的代码:

time=1
total=5
for number in $(seq "$2")
do
    echo "$time + $total" | bc
done

给出:seq:无效的浮点参数:'' 尝试'seq --help'以获取更多信息。有人可以告诉我如何解决吗?

bash
  • 1 个回答
  • 156 Views
Martin Hope
Yunfei Chen
Asked: 2021-06-18 12:54:19 +0800 CST

使用 sed 提取特定列

  • -1

我只是想知道如何使用 sed 提取特定列?(我的系统已经安装了 sed,所以不幸的是没有 awk :()。我得到了一个如下文本文件:

Business Name,Description,Address,Postal Code,Email,Phone,Fax,Web Site,City,Latitude,Longitude,Keywords,Mailing Address,Indigenous Ownership,Region,Type,Industry Sector,Year Formed,Number of Employees,Primary Contact,Contact Title,Twitter,Facebook,When Updated
Duz Cho Construction LP,"Duz Cho Construction is an earthworks construction company doing site development, road access, and reclamation for the oil and gas, wind energy, mining and other civil works construction within the traditional territory of McLeod Lake Indian Band.",4821 South Access Road,V0C 1J0,[email protected],250-788-3120,250-788-3188,https://duzcho.com/duz-cho-construction/,Chetwynd,55.6963381,-121.6266684,Duz Cho Construction LP  23  Construction,"4821 South Access Road, Chetwynd, BC V0C 1J0",TRUE,Northeast,Community Owned Company,23  Construction,2002,55 to 99,Jacob Albertson,General Manager,,https://www.facebook.com/DuzChoConstruction/,2012-04-15
Gilwa Consulting Inc.,"Gilwa Consulting Inc. (GCI) is an Indigenous owned and operated business that provides advisory services for all participants in the construction industry engaged in developing, implementing, and/or executing on contractual agreements between Indigenous peoples, industry (EPC, EPCM, Contractors), and/or government.",710 Ruston Road,V1X3Y2,[email protected],778-215-1888,,http://www.gilwaconsulting.com,Kelowna,49.8804877,-119.4070893,"Gilwa Consulting Inc. 54  Professional, scientific and technical services","710 Ruston Road, Kelowna, BC V1X 3Y2",TRUE,Thompson / Okanagan,Private Company,"54  Professional, scientific and technical services",2019,1 to 4,Thomas Nyce,Director,,,2021-04-14
HSI  Hobbs Strategic Insights,"Offering a full suite of strategic planning, business consultation, corporate communications and success & inclusion coaching services, HSI works with you to manifest transformational initiatives from conception to implementation. HSI is a leader in Indigenous reconciliation work, and diversity & inclusion initiatives for corporate entities.",,V3M 0J4,[email protected],604-626-8296,,https://strategicinsights.ca,,,,"HSI  Hobbs Strategic Insights 54  Professional, scientific and technical services",,TRUE,Lower Mainland / Southwest,Private Company,"54  Professional, scientific and technical services",2021,1 to 4,Sasha Hobbs,Principal Strategist,,,2021-04-14
Bigfoot Donuts,"Bigfoot Donuts is a locally owned and operated bakery and caf in the heart of Downtown Courtenay. Specializing in handcrafted, made from scratch, quality, coffee and donuts, with a side of fun.",463 A 5th Street,V9N 1J7,[email protected],250-871-6603,,https://www.bigfootdonuts.com/,Courtenay,49.6902502,-125.0032691,Bigfoot Donuts 72  Accommodation and food services,"463 A 5th Street, Courtenay BC V9N 1J7",TRUE,Vancouver Island and Coast,Private Company,72  Accommodation and food services,2017,5 to 9,Lyndsey Bell,Owner,,https://www.facebook.com/Bigfoot.Donuts/,2021-04-14
Refocus Communications & Fundraising,"Refocus helps non-profit organizations more deeply engage their community and supporters so that, together, they can do great things in the world.
We work with charities across Canada, helping them build fundraising programs with an engagement and communications focus.","20543 96 Ave., Unit 31",V1M 3W3,[email protected],778.875.3439,,http://www.refocuscommunications.com,Langley ,49.1776159,-122.6564416,Refocus Communications & Fundraising 81  Other services (except public administration),"20543 96 Ave., Unit 31, Langley, BC V1M 3W3",TRUE,Lower Mainland / Southwest,Private Company,81  Other services (except public administration),2017,1 to 4,Aime Lindenberger,"CEO, Chief Engagement Officer",,,2021-03-31
Turtle Island Connections,"Turtle Island Connections curates Subscription boxes filled with Indigenous creations. Our box, the Turtle Shell, focuses on our spiritual, mental, emotional, and physical well-being. Each Shell contains Indigenous art, Cultural teachings, Nourishment, Self-care products and Donation to the Vancouver Aboriginal Health Society.",3139 Brandt Crescent,V9L 6W6,[email protected],250.710.7685,,https://www.turtleislandconnections.ca,Duncan,48.7633914,-123.7137629,Turtle Island Connections 44-45  Retail trade,"3139 Brandt Crescent, Duncan BC V9L 6W6",TRUE,Vancouver Island and Coast,Partnership,44-45  Retail trade,2021,1 to 4,Lindsay Myers,Co-Founder,,https://www.facebook.com/TurtleIslandConnections,2021-03-31
Bulkley Valley Roofing Ltd,"Specializing in Commercial, Industrial and Residential Roofing. Fully certified and insured for hot roofing work. Red-seal Journeymen staffed.","Unit 3-3167 Tatlow rd, ",V0J 2N0,[email protected],250-846-9446,250-846-9440,,Smithers,54.7698334,-127.143943,Bulkley Valley Roofing Ltd 23  Construction,"Unit 3-3167 Tatlow rd, Smithers BC V0J 2N0",TRUE,North Coast,Development Corporation,23  Construction,2000,5 to 9,Murray Olivier,Owner/operator,,,2021-03-31
North Coast Helicopters,Northcoast Helicopters provides experienced long-line pilots who are seasoned in diamond drill support and mountain flying. Northcoast Helicopters provides wildfire fighting services to various private and government agencies.,2555 Seal Cove Road unit 123,V8J 3P6,[email protected],250-631-6031,,http://www.northcoasthelicopters.com,Prince Rupert,54.3369741,-130.3125632,"North Coast Helicopters 21  Mining, quarrying, and oil and gas extraction","2555 Seal Cove Road unit 123, Prince Rupert BC V8J 3P6",TRUE,North Coast,Private Company,"21  Mining, quarrying, and oil and gas extraction",2005,5 to 9,Kristen,Owner,,,2021-03-31
Park West Professional Services,Call Center,"Suite 811, 100 Park Royal, Suite 200",V7T 1A2,[email protected],604-210-1483,,,West Vancouver,49.3251879,-123.1358334,"Park West Professional Services 54  Professional, scientific and technical services","100 Park Royal, Suite 200, West Vancouver, BC V7T 1A2",TRUE,Lower Mainland / Southwest,Private Company,"54  Professional, scientific and technical services",2013,10 to 19,Matt Vickers,Owner,,,2021-03-31
Afterglow Hair Lounge,"Get your glow on. We strive to provide our guests the same quality one-on-one service small towns are renowned for, with the style, talent and professionalism of the city. We're proud to have been nominated and featured as some of the ""Best of Powell River"" stylists in 2017, 2018, 2019 and 2020 and have a shared dedication to maintain improve client experiences in years to come.  Look no further for the best wedding stylists of the upper Sunshine Coast  available year-round for events in-salon*, seven days a week. Come experience AfterGlow.",7075 Alberni Street,V8A2C2,[email protected],604.485.2075,, http://www.afterglowhairlounge.com,Powell River,49.8468725,-124.5196439,Afterglow Hair Lounge 81  Other services (except public administration),,TRUE,Vancouver Island and Coast,Private Company,81  Other services (except public administration),2011,5 to 9,Holly Barnes,Owner/operator,https://twitter.com/afterglowhair,https://www.facebook.com/AfterGlowHairLounge,2021-03-10
Dawson Analytics Inc.,"Dawson Analytics is a consulting company specializing in research development and design, data analysis and interpretation, and program/policy evaluation. Our company sources and analyzes data to provide our clients with powerful insights into their processes, outcomes and future endeavours.",22839 Gilbert Drive,V4R 0G4,[email protected],604.961.5129,,http://www.dawsonanalytics.com,Maple Ridge,49.2512469,-122.5874728,Dawson Analytics Inc.  51  Information and cultural industries,"22839 Gilbert Drive, Maple Ridge, BC V4R 0G4",TRUE,Lower Mainland / Southwest,Private Company,51  Information and cultural industries,2021,1 to 4,Stephanie Johnston,Vice President,,,2021-03-10
Bridging Innovations Inc.,Management consulting and Aboriginal relations services,,V2B 4G5,[email protected],250.571.9566,,https://bridginginnovations.com,Kamloops BC,50.6745,-120.3273, Bridging Innovations Inc. 55  Management of companies and enterprises,Postal Code: V4R 0G4,TRUE,Thompson / Okanagan,Private Company,55  Management of companies and enterprises,1997,1 to 4,Bob Miller,Onwer & President,,,2021-03-10
Fraser Valley Office Systems,"Fraser Valley Office Systems is a First Nation owned authorized Ricoh dealership. Ricohs leading edge approach to technology and document workflow have helped many corporations streamline document production and increase efficiency while reducing costs.As the Fraser Valley's Local Authorized Ricoh Dealer, we have partnered with Ricoh to bring you the latest office system solutions for your copying, printing, scanning, faxing, and document management needs. We pride ourselves on offering exemplary all-inclusive service to our customers. We take the time to analyze and understand your print, copy, and document management needs so that we can provide you with a solution that saves you time, money, and hassle. We have locations across BC and Yukon to offer service across western Canada. Our ownership group is the Tle Nax Tawei Group (TTG) is the business arm of the Teslin Tlingit First Nation and is owned by the Teslin Tlingit Council Business Trust. TleNax Tawei Limited Partnership (TTLP) and TleNax Tawei Industrial Limited Partnership (TTLPI) are business holding partnerships, managed by one partner Tle Nax Tawei Inc. TTG strives to provide the Trust with good financial returns and promotes self-sufficiency for the Teslin Tlingit First Nation.",Unit 4-2582 Mount Lehman Rd. ,V4X2N3,[email protected],604.621.3866,,http://fraservalleyofficesystems.com/,Abbotsford,49.0490255,-122.3828463,"Fraser Valley Office Systems 54  Professional, scientific and technical services",Unit 4-2582 Mount Lehman Rd. Abbotsford BC V4X2N3,TRUE,Lower Mainland / Southwest,Community Owned Company,"54  Professional, scientific and technical services",2016,10 to 19,Jonathan Nickel,Business Development Manager,,,2021-03-05
Shxw'owhamel Ventures,"Shxw?whml Ventures is a proud Indigenous owned and operated construction company based within Shxw?whml First Nation traditional territory in Hope, BC. We have a diverse set of service offerings with vast experience to take on any project, big or small. With a highly skilled Indigenous and local workforce, we have the capacity to deliver high quality work and products. List of services include: Heavy Civil, structural building, underground utilities, environmental construction, safety and security, camp construction, equipment hauling and more.",58700-A St. Elmo Rd.,V0X1L2, [email protected],604-860-9760,,https://shxwowhamelventures.ca/,Hope,49.3512554,-121.5934023,Shxw'owhamel Ventures 23 - Construction,"58700-A St Elmo Rd, Hope, BC V0X 1L2",TRUE,Lower Mainland / Southwest,: Community Owned Company,23  Construction,2015,20 to 49,Alfred James,CEO,https://twitter.com/ShxwowhamelVLP,https://www.facebook.com/ShxwowhamelVentures,2021-03-05
Surely Building Company Inc.,Our ownership group is the Tle Nax Tawei Group (TTG) is the business arm of the Teslin Tlingit First Nation and is owned by the Teslin Tlingit Council Business Trust.,3592 Turner Street,V5K 2H9,[email protected],250.793.7300,,,Vancouver,49.27882,-123.0283148,Surely Building Company Inc. 23  Construction,"3592 Turner Street, Vancouver, BC",TRUE,Lower Mainland / Southwest,Private Company,23  Construction,2021,1 to 4,Landan Churchill,Owner,,,2021-02-22
West Coast Pile Driving 2013 Ltd,"We supply and install driven foundation piles, sheet pile shoring, and various other ground improvement technologies.",12955 Katonien Street,V2W0J2,[email protected],604.803.6569,,http://www.westcoastpiledriving.com,Maple Ridge,49.2377,-122.49499,West Coast Pile Driving 2013 Ltd 23  Construction,"12955 Katonien Street, Maple Ridge V2W0J2",TRUE,Lower Mainland / Southwest,Private Company,23  Construction,2013,1 to 4,Ryan Johnston, President,,,2021-02-22
Indigenous Canada Solutions Ltd. (ICS),Ricohs leading edge approach to technology and document workflow have helped many corporations streamline document production and increase efficiency while reducing costs.,401-4th Avenue West,V8J 1P7,[email protected],,,,Prince Rupert,54.31194,-130.3232,"Indigenous Canada Solutions Ltd. (ICS) 54  Professional, scientific and technical services","401-4th Avenue West, Prince Rupert, BC V8J1P7",TRUE,North Coast,Private Company,"54  Professional, scientific and technical services",2020,1 to 4,Maynard Angus,President,,,2021-02-22
New Age Furnace and Duct Cleaning Ltd.,,2860 Auburn Road ,V4T3B2,[email protected],780.937.3907,,https://newageductcleaning.business.site/,West Kelowna,49.855711,-119.603322,New Age Furnace and Duct Cleaning Ltd. 81  Other services (except public administration),2860 Auburn Road West Kelowna V4T3B2,TRUE,Thompson / Okanagan,,81  Other services (except public administration),2018,1 to 4,Candace Landry,Owner,,,2021-02-22
BGW FILM STUDIOS,I am focusing on the self-reliance and independence of the indigenous people by creating documentary films that highlight students and professionals.,"7-1451 Perkins Road, ", V9W4R8,[email protected],250.850.9344,,http://www.bgwfilmstudios.com,Campbell River,50.0472431,-125.2730345,BWG FILM 81  Other services (except public administration),": 7-1451 Perkins Road, Campbell River, BC V9W4R8",TRUE,Vancouver Island and Coast,Private Company,81  Other services (except public administration),2013,1 to 4,Billy George Williams,Owner / WEO, https://twitter.com/bgwfilmstudios,https://www.facebook.com/BGWFILMSTUDIOS,2021-02-22
The Owls Path,"As the Fraser Valley's Local Authorized Ricoh Dealer, we have partnered with Ricoh to bring you the latest office system solutions for your copying, printing, scanning, faxing, and document management needs.",2975 3rd Ave ,V9Y 9B4,[email protected],250-206-1674,, http://www.theowlspathmarket.com,Port Alberni,49.2331419,-124.8093691,"The Owls Path 71  Arts, entertainment and recreation","2975 3rd Ave, Port Alberni, BC V9

文件中有很多行还有更多行,但我猜这已经足够了。现在我需要提取 Business Name 列中的信息。所以我尝试了:

sed -n '^[^,]*,{1}p' $1

其中 $1 是从用户输入读取的文件名。我也试过:

sed -n '\^\[\^,\]*,{1}p' $1

我更熟悉 grep RE,这就是为什么它们看起来像 grep RE 而不是 sed 的原因。最近才开始使用 sed。

sed
  • 1 个回答
  • 1231 Views
Martin Hope
Yunfei Chen
Asked: 2021-06-11 14:58:06 +0800 CST

Grep 模式匹配不起作用?

  • 0

我有一个像这样的文本文件:

"Id","District Name","Neighborhood Name","Street","Weekday","Month","Day","Hour","Part of the day","Mild injuries","Serious injuries","Victims","Vehicles involved","Longitude","Latitude"
"2017S008429    ","Unknown","Unknown","Número 27                                         ","Friday","October",13,8,"Morning",2,0,2,2,2.12562442,41.34004482
"2017S007316    ","Unknown","Unknown","Número 3 Zona Franca / Número 50 Zona Franca      ","Friday","September",1,13,"Morning",2,0,2,2,2.12045245,41.33942606
"2017S010210    ","Unknown","Unknown","Litoral (Besòs)                                   ","Friday","December",8,21,"Afternoon",5,0,5,2,2.1673561,41.3608855
"2017S006364    ","Unknown","Unknown","Número 3 Zona Franca                              ","Friday","July",21,2,"Night",1,0,1,2,2.12452894,41.33766786
"2017S004615    ","Sant Martí","el Camp de l'Arpa del Clot","Las Navas de Tolosa                               ","Thursday","May",25,14,"Afternoon",1,0,1,3,2.185272,41.416365
"2017S007775    ","Sant Martí","el Camp de l'Arpa del Clot","Indústria / Trinxant                              ","Wednesday","September",20,12,"Morning",1,0,1,2,2.183245,41.416336
"2017S004484    ","Sant Martí","el Camp de l'Arpa del Clot","Trinxant / Indústria                              ","Saturday","May",20,21,"Afternoon",1,0,1,2,2.183245,41.416336
"2017S010680    ","Sant Martí","el Camp de l'Arpa del Clot","Indústria                                         ","Tuesday","December",26,20,"Afternoon",2,0,2,1,2.183561,41.416372
"2017S005152    ","Sant Martí","el Camp de l'Arpa del Clot","Indústria                                         ","Monday","June",12,15,"Afternoon",1,0,1,1,2.184059,41.416763
"2017S003932    ","Sant Martí","el Camp de l'Arpa del Clot","Maragall                                          ","Wednesday","May",3,20,"Afternoon",1,0,1,1,2.181225,41.413958
"2017S010348    ","Sant Martí","el Camp de l'Arpa del Clot","Indústria                                         ","Thursday","December",14,20,"Afternoon",1,0,1,2,2.18229,41.415772
"2017S000245    ","Sant Martí","el Camp de l'Arpa del Clot","ST ANTONI M CLARET / Pg Maragall                  ","Wednesday","January",11,7,"Morning",1,0,1,2,2.180453,41.41579
"2017S005695    ","Sant Martí","el Camp de l'Arpa del Clot","Sant Antoni Maria Claret / Guinardó               ","Friday","June",30,12,"Morning",1,0,1,2,2.18114,41.416295
"2017S007384    ","Sant Martí","el Camp de l'Arpa del Clot","Sant Antoni Maria Claret                          ","Monday","September",4,16,"Afternoon",0,1,1,2,2.176324,41.412546
"2017S008080    ","Sant Martí","el Camp de l'Arpa del Clot","Sant Antoni Maria Claret                          ","Saturday","September",30,19,"Afternoon",1,0,1,2,2.176324,41.412546
"2017S003439    ","Sant Martí","el Camp de l'Arpa del Clot","Còrsega / Còrsega                                 ","Monday","April",17,14,"Afternoon",1,0,1,2,2.178314,41.410784
"2017S002410    ","Sant Martí","el Camp de l'Arpa del Clot","CÒRSEGA / Dos de Maig                             ","Saturday","March",25,14,"Afternoon",4,0,4,2,2.177719,41.410323
"2017S009296    ","Sant Martí","el Camp de l'Arpa del Clot","Indústria                                         ","Thursday","November",9,22,"Night",1,0,1,1,2.17674,41.411445

我试过类似的东西:

grep "May ,25" $1

用户输入的文件名在哪里$1。所以基本上它应该找到包含日期 May, 25 的行,但它绝对没有显示任何内容。我知道有些行包含日期 5 月 25 日。

我也尝试了以下方法,但它仍然不起作用:

grep "\"May\" ,25" $1

我究竟做错了什么?

grep
  • 1 个回答
  • 61 Views
Martin Hope
Yunfei Chen
Asked: 2021-06-10 10:23:56 +0800 CST

使用 Grep 进行模式匹配

  • 1

我正在尝试为我的文件找到一个特定的值,这是一个快速的片段:

PRODUCT_TYPE_NAME,PRODUCT_CLASS_NAME,PRODUCT_SUB_CLASS_NAME,PRODUCT_MINOR_CLASS_NAME,PRODUCT_COUNTRY_ORIGIN_NAME,PRODUCT_SKU_NO,PRODUCT_LONG_NAME,PRODUCT_BASE_UPC_NO,PRODUCT_LITRES_PER_CONTAINER,PRD_CONTAINER_PER_SELL_UNIT,PRODUCT_ALCOHOL_PERCENT,CURRENT_DISPLAY_PRICE,SWEETNESS_CODE
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,CANADA,198267,COPPER MOON - MALBEC,48162013513,3,1,14,30.99,0
LIQUOR,WINE,TABLE WINE,TABLE WINE WHITE,CANADA,305375,DOMAINE D'OR - DRY,48162001886,4,1,11.5,32.99,0
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,CANADA,53017,SOMMET ROUGE,58976055050,4,1,12,29.99,0
LIQUOR,WINE,TABLE WINE,TABLE WINE WHITE,CANADA,215525,MISSION RIDGE - PREMIUM DRY WHITE,779646155251,4,1,11,33.99,1
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,UNITED STATES OF AMERICA,168971,ZINFANDEL - BIG HOUSE CARDINAL ZIN,81308001456,3,1,13.5,36.99,0
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,FRANCE,234559,LE VILLAGEOIS RED - CELLIERS LA SALLE,63657001448,4,1,11,34.99,0
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,CANADA,492314,SAWMILL CREEK - MERLOT,63657004074,16,1,12.5,119,0
LIQUOR,WINE,TABLE WINE,TABLE WINE WHITE,CANADA,587584,SOLA,63657006566,4,1,12,32.99,0
LIQUOR,WINE,TABLE WINE,TABLE WINE WHITE,CANADA,100925,GANTON & LARSEN PROSPECT - PINOT BLANC BIRCH CANOE 2011,776545400000,0.75,1,11.5,13.99,0
LIQUOR,SPIRITS,IRISH WHISKY,IRISH WHISKY,IRELAND,10157,JAMESON - IRISH,80432500170,0.75,1,40,34.99,NA
LIQUOR,WINE,TABLE WINE,TABLE WINE WHITE,ITALY,102764,PINOT GRIGIO DELLE VENEZIE - RUFFINO LUMINA,8001660197156,0.75,1,12.5,15.99,0
LIQUOR,SPIRITS,AMERICAN WHISKY,AMERICAN WHISKY,UNITED STATES OF AMERICA,103747,MAKER'S MARK - KENTUCKY BOURBON,85246139431,0.75,1,45,44.95,NA
LIQUOR,SPIRITS,GIN,DRY GIN,CANADA,1040,GORDONS - LONDON DRY,622153139040,0.75,1,40,24.49,NA
LIQUOR,WINE,TABLE WINE,TABLE WINE WHITE,CANADA,104679,CALONA - ARTIST SERIES RESERVE PINOT GRIS 2011/13,58976501656,0.75,1,13.5,12.99,0
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,UNITED STATES OF AMERICA,106476,PINOT NOIR - SIDURI RUSSIAN RIVER 11/12,626990184140,0.75,1,14.5,49.99,0
LIQUOR,SPIRITS,CACHACA,CACHACA,BRAZIL,107029,CACHACA 61,7896547500676,0.7,1,40,28.95,2
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,FRANCE,109082,CHATEAU PAVIE DECESSE 2008,,0.75,1,13,239,0
LIQUOR,SPIRITS,SCOTCH WHISKY,SCOTCH - BLEND,UNITED KINGDOM,1099,JOHNNIE WALKER - RED LABEL,622153631049,0.75,1,40,29.99,NA
LIQUOR,WINE,TABLE WINE,TABLE WINE RED,ITALY,110460,LE CONTRADE - CO.PRO.VI,8004753004010,1,1,12,9.9,0
LIQUOR,SPIRITS,RUM,DARK,CANADA,112433,BACARDI - BLACK,620213055408,0.75,1,40,23.75,NA
LIQUOR,WINE,APERITIF  DESSERT AND FORTIFIED WINE,MONTILLA,SPAIN,112789,ALVEAR - MEDIUM DRY,766238303374,0.75,1,17,17.99,3
LIQUOR,SPIRITS,SCOTCH WHISKY,SCOTCH - BLEND,UNITED KINGDOM,112896,JOHNNIE WALKER - RED LABEL,622153631070,1.75,1,40,68.99,NA

现在我需要使用 grep,如果解决方案不涉及 sed、perl、awk 或循环,我会更喜欢。我试过了:

grep -E "^.*(,.*){9}[^0]+" BC_Liquor_Store_Product_Price_List.csv

但这显然得到了一切。我需要获取所有具有 PRODUCT_LITRES_PER_CONTAINER >= 1 的行,但我无法弄清楚如何。.* 得到一切,但在 之前,有一些词,所以我不能这样做:

grep -E "^(,.*){9}[^0]+" BC_Liquor_Store_Product_Price_List.csv

只会匹配以 ,? 开头的行

command-line
  • 1 个回答
  • 108 Views
Martin Hope
Yunfei Chen
Asked: 2021-06-04 12:45:59 +0800 CST

基于文本文件的排序

  • 0

我正在尝试根据列中的第二个字段对文本文件进行排序,所以基本上我有一个像

"Year","District Code","District Name","Neighborhood Code","Neighborhood Name","Gender","Number"
"2017","1","Ciutat Vella","1","el Raval","Boys",283
"2017","1","Ciutat Vella","2","el Barri Gòtic","Boys",56
"2017","1","Ciutat Vella","3","la Barceloneta","Boys",51
"2017","1","Ciutat Vella","4","Sant Pere, Santa Caterina i la Ribera","Boys",90
"2017","2","Eixample","5","el Fort Pienc","Boys",117
"2017","2","Eixample","6","la Sagrada Família","Boys",207
"2017","2","Eixample","7","la Dreta de l'Eixample","Boys",185
"2017","2","Eixample","8","l'Antiga Esquerra de l'Eixample","Boys",176
"2017","2","Eixample","9","la Nova Esquerra de l'Eixample","Boys",218
"2017","2","Eixample","10","Sant Antoni","Boys",172
"2017","3","Sants-Montjuïc","11","el Poble Sec","Boys",156
"2017","3","Sants-Montjuïc","12","la Marina del Prat Vermell","Boys",4
"2017","3","Sants-Montjuïc","13","la Marina de Port","Boys",119
"2017","3","Sants-Montjuïc","14","la Font de la Guatlla","Boys",42
"2017","3","Sants-Montjuïc","15","Hostafrancs","Boys",78
"2017","3","Sants-Montjuïc","16","la Bordeta","Boys",81
"2017","3","Sants-Montjuïc","17","Sants - Badal","Boys",108
"2017","3","Sants-Montjuïc","18","Sants","Boys",155
"2017","4","Les Corts","19","les Corts","Boys",199
"2017","4","Les Corts","20","la Maternitat i Sant Ramon","Boys",101
"2017","4","Les Corts","21","Pedralbes","Boys",32
"2017","5","Sarrià-Sant Gervasi","22","Vallvidrera, el Tibidabo i les Planes","Boys",17
"2017","5","Sarrià-Sant Gervasi","23","Sarrià","Boys",122
"2017","5","Sarrià-Sant Gervasi","24","les Tres Torres","Boys",74
"2017","5","Sarrià-Sant Gervasi","25","Sant Gervasi - la Bonanova","Boys",104
"2017","5","Sarrià-Sant Gervasi","26","Sant Gervasi - Galvany","Boys",206
"2017","5","Sarrià-Sant Gervasi","27","el Putxet i el Farró","Boys",127
"2017","6","Gràcia","28","Vallcarca i els Penitents","Boys",66
"2017","6","Gràcia","29","el Coll","Boys",26
"2017","6","Gràcia","30","la Salut","Boys",62
"2017","6","Gràcia","31","la Vila de Gràcia","Boys",241
"2017","6","Gràcia","32","el Camp d'en Grassot i Gràcia Nova","Boys",149
"2017","7","Horta-Guinardó","33","el Baix Guinardó","Boys",97
"2017","7","Horta-Guinardó","34","Can Baró","Boys",41
"2017","7","Horta-Guinardó","35","el Guinardó","Boys",148
"2017","7","Horta-Guinardó","36","la Font d'en Fargues","Boys",26
"2017","7","Horta-Guinardó","37","el Carmel","Boys",123
"2017","7","Horta-Guinardó","38","la Teixonera","Boys",48
"2017","7","Horta-Guinardó","39","Sant Genís dels Agudells","Boys",28
"2017","7","Horta-Guinardó","40","Montbau","Boys",26
"2017","7","Horta-Guinardó","41","la Vall d'Hebron","Boys",12
"2017","7","Horta-Guinardó","42","la Clota","Boys",8
"2017","7","Horta-Guinardó","43","Horta","Boys",9

我想根据 District code 对整个文件进行排序,然后打印出结果,我只是在这里复制了几行,因为文件有 1000 多行所以。我尝试了几个命令:

cat $1 | sort -n -k 2
cat $1 | sort -t \" -n -k 2

但它似乎什么都不做?

还有一些行未排序,例如:

"2017","10","Sant Martí","64","el Camp de l'Arpa del Clot","Boys",148
"2017","10","Sant Martí","65","el Clot","Boys",125
"2017","10","Sant Martí","66","el Parc i la Llacuna del Poblenou","Boys",79
"2017","10","Sant Martí","67","la Vila Olímpica del Poblenou","Boys",34
"2017","10","Sant Martí","68","el Poblenou","Boys",160
"2017","10","Sant Martí","69","Diagonal Mar i el Front Marítim del Poblenou","Boys",103
"2017","10","Sant Martí","70","el Besòs i el Maresme","Boys",119
"2017","10","Sant Martí","71","Provençals del Poblenou","Boys",106
"2017","10","Sant Martí","72","Sant Martí de Provençals","Boys",100
"2017","10","Sant Martí","73","la Verneda i la Pau","Boys",122
"2017","1","Ciutat Vella","1","el Raval","Girls",219
"2017","1","Ciutat Vella","2","el Barri Gòtic","Girls",53
"2017","1","Ciutat Vella","3","la Barceloneta","Girls",50
"2017","1","Ciutat Vella","4","Sant Pere, Santa Caterina i la Ribera","Girls",90
"2017","2","Eixample","5","el Fort Pienc","Girls",114
"2017","2","Eixample","6","la Sagrada Família","Girls",183
"2017","2","Eixample","7","la Dreta de l'Eixample","Girls",159

所以以防万一你想知道。谢谢...

text-processing
  • 2 个回答
  • 173 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve